forked from sachinkesiraju/SwiftExample
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMapViewController.swift
More file actions
82 lines (60 loc) · 2.61 KB
/
Copy pathMapViewController.swift
File metadata and controls
82 lines (60 loc) · 2.61 KB
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
78
79
80
81
82
//
// MapViewController.swift
// SwiftExample
//
// Created by Sachin Kesiraju on 7/15/14.
// Copyright (c) 2014 Sachin Kesiraju. All rights reserved.
//
import UIKit
import MapKit
import CoreLocation
class MapViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate {
@IBOutlet var mapView : MKMapView?
override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
// Custom initialization
}
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
// self.mapView.delegate = self
let location = "1 Infinity Loop, Cupertino, CA"
var geocoder:CLGeocoder = CLGeocoder()
geocoder.geocodeAddressString(location, completionHandler: {(placemarks, error) -> Void in
if((error) != nil){
println("Error", error)
}
else if let placemark = placemarks?[0] as? CLPlacemark {
var placemark:CLPlacemark = placemarks[0] as! CLPlacemark
var coordinates:CLLocationCoordinate2D = placemark.location.coordinate
var pointAnnotation:MKPointAnnotation = MKPointAnnotation()
pointAnnotation.coordinate = coordinates
pointAnnotation.title = "Apple HQ"
self.mapView?.addAnnotation(pointAnnotation)
self.mapView?.centerCoordinate = coordinates
self.mapView?.selectAnnotation(pointAnnotation, animated: true)
println("Added annotation to map view")
}
})
}
func mapView (mapView: MKMapView!,
viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! {
var pinView:MKPinAnnotationView = MKPinAnnotationView()
pinView.annotation = annotation
pinView.pinColor = MKPinAnnotationColor.Red
pinView.animatesDrop = true
pinView.canShowCallout = true
return pinView
}
func mapView(mapView: MKMapView!,
didSelectAnnotationView view: MKAnnotationView!){
println("Selected annotation")
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}