-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDetailViewController.swift
79 lines (67 loc) · 2.7 KB
/
DetailViewController.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//
// DetailViewController.swift
// Yelp
//
// Created by Andrei Gurau on 1/29/16.
// Copyright © 2016 Timothy Lee. All rights reserved.
//
import UIKit
import MapKit
class DetailViewController: UIViewController, MKMapViewDelegate{
@IBOutlet weak var mapView: MKMapView!
var business: Business!
override func viewDidLoad() {
super.viewDidLoad()
mapView.delegate = self
var latitude = business.location!["coordinate"]!["latitude"]! as! Double
var longitude = business.location!["coordinate"]!["longitude"]! as! Double
let centerLocation = CLLocation(latitude: latitude, longitude: longitude)
goToLocation(centerLocation)
var coordinates = centerLocation.coordinate
addAnnotationAtCoordinate(coordinates)
navigationItem.title = business.name
}
func goToLocation(location: CLLocation) {
let span = MKCoordinateSpanMake(0.005, 0.005)
let region = MKCoordinateRegionMake(location.coordinate, span)
mapView.setRegion(region, animated: false)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func addAnnotationAtCoordinate(coordinate: CLLocationCoordinate2D) {
print("function called")
let annotation = MKPointAnnotation()
annotation.coordinate = coordinate
annotation.title = "An annotation"
mapView.addAnnotation(annotation)
//mapView(mapView, viewForAnnotation: annotation)
}
func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {
let identifier = "customAnnotationView"
// custom pin annotation
print("mapview function called")
var annotationView = mapView.dequeueReusableAnnotationViewWithIdentifier(identifier) as? MKPinAnnotationView
if (annotationView == nil) {
annotationView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: identifier)
}
else {
annotationView!.annotation = annotation
}
if #available(iOS 9.0, *) {
annotationView!.pinTintColor = UIColor.greenColor()
} else {
// Fallback on earlier versions
}
return annotationView
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}