[IOS] 지도 : Maps into your App
#1. 목표
- 앱에 맵뷰를 넣어서 지도를 올려보자.
- 원하는 지역 호출
- 핀 설정
- 지역 설명: 타이틀, 설명
- 추가 설정
#2. 정리
1. 위도와 경도 값을 정한다.
2. 맵의 척도 값을 정한다.
3. 위도 경도를 CLLocationCoordinate2DMake에 넣어준다.
4. 맵의 척도를 MKCoordinateSpanMake에 넣는다.
5. 3,4번을 MKCoordinateRegionMake값에 넣어서 변수 region으로 설정한다.
6. annotation을 통해 지명을 표시
7. 새로운 지역 설정: UILongPressGestureRecognizer
- 마우스 클릭으로 안되고 있음
#3. 소스
//
// ViewController.swift
// Map Demo
//
// Created by Rob Percival on 03/03/2015.
// Copyright (c) 2015 Appfish. All rights reserved.
//
import UIKit
import MapKit
class ViewController: UIViewController, MKMapViewDelegate {
@IBOutlet var map: MKMapView!
override func viewDidLoad() {
super.viewDidLoad()
// 43.095181, -79.006424
//NOTE: you can change the 'var' variables to 'let'. It will work the same, and remove the warnings
var latitude:CLLocationDegrees = 43.095181
var longitude:CLLocationDegrees = -79.006424
var latDelta:CLLocationDegrees = 0.01
var lonDelta:CLLocationDegrees = 0.01
var span:MKCoordinateSpan = MKCoordinateSpanMake(latDelta, lonDelta)
var location:CLLocationCoordinate2D = CLLocationCoordinate2DMake(latitude, longitude)
var region:MKCoordinateRegion = MKCoordinateRegionMake(location, span)
map.setRegion(region, animated: false)
var annotation = MKPointAnnotation()
annotation.coordinate = location
annotation.title = "Niagra Falls"
annotation.subtitle = "One day I'll go here..."
map.addAnnotation(annotation)
var uilpgr = UILongPressGestureRecognizer(target: self, action: "action:")
uilpgr.minimumPressDuration = 2
map.addGestureRecognizer(uilpgr)
}
func action(gestureRecognizer: UIGestureRecognizer) {
print("Gesture Recognized")
var touchPoint = gestureRecognizer.locationInView(self.map)
var newCoordinate: CLLocationCoordinate2D = map.convertPoint(touchPoint, toCoordinateFromView: self.map)
var annotation = MKPointAnnotation()
annotation.coordinate = newCoordinate
annotation.title = "New Place"
annotation.subtitle = "One day I'll go here..."
map.addAnnotation(annotation)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}

"파트너스 활동을 통해 일정액의 수수료를 제공받을 수 있음"