[Swift] Notebook

Swfit - MapKit 사용하기 예제

Dev2DHs 2016. 4. 18. 16:05





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
//ViewController
 
import UIKit
import MapKit
import CoreLocation
 
class ViewController: UIViewController {
 
    @IBOutlet weak var maps: MKMapView!
    override func viewDidLoad() {
        super.viewDidLoad()
        // location 값과 span(얼마나 확대할거냐) 지정
        
        var location = CLLocationCoordinate2DMake(48.87146,    2.35500)
        var span = MKCoordinateSpan(latitudeDelta: 0.02,longitudeDelta: 0.02)
        var region = MKCoordinateRegion(center: location, span : span)
        
        var annotation = MKPointAnnotation()
        annotation.coordinate = location
        annotation.title = "My Office"
        annotation.subtitle = "Check for Alert"
        
        maps.setRegion(region, animated: true)
        maps.addAnnotation(annotation)
        
        
    }
 
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
 
 
}
cs