2016-08-16 2 views
1

Как получить имя местоположения из точек местоположения Mapkit по умолчанию в iOS.Как получить имя места из аннотаций по умолчанию Mapkit в iOS

Я хочу нажать на нее (ex.Swiss отель) и получить имя в Swift

enter image description here

+0

вы можете показать ваш код попробовал –

+0

@ Anbu.Karthik Пока у меня нет кода, просто viewcontroller с mapview. Я могу создать свои собственные аннотации, но я также хочу использовать текущие местоположения MapView – Arda

ответ

3

шаг 1

добавить жест на карте

let tgr = UITapGestureRecognizer(target: self, action: #selector(self.tapGestureHandler)) 
tgr.delegate = self 
mapView.addGestureRecognizer(tgr) 

этап-2

получить coodinates на затронутых местах, как

func tapGestureHandler(tgr: UITapGestureRecognizer) 
{ 
let touchPoint = tgr.locationInView(yourmapview) 
let touchMapCoordinate = yourmapview.convertPoint(touchPoint, toCoordinateFromView: yourmapview) 
print("tapGestureHandler: touchMapCoordinate = \(touchMapCoordinate.latitude),\(touchMapCoordinate.longitude)") 
} 

шаг-3

наконец преобразовать широты и долго для решения

let geoCoder = CLGeocoder() 
    let location = CLLocation(latitude: touchMapCoordinate.latitude, longitude: touchMapCoordinate.longitude) 

    geoCoder.reverseGeocodeLocation(location, completionHandler: { (placemarks, error) -> Void in 

     // Place details 
     var placeMark: CLPlacemark! 
     placeMark = placemarks?[0] 

     // Address dictionary 
     print(placeMark.addressDictionary) 

     // Location name 
     if let locationName = placeMark.addressDictionary!["Name"] as? NSString { 
      print(locationName) 
     } 

     // Street address 
     if let street = placeMark.addressDictionary!["Thoroughfare"] as? NSString { 
      print(street) 
     } 

     // City 
     if let city = placeMark.addressDictionary!["City"] as? NSString { 
      print(city) 
     } 

     // Zip code 
     if let zip = placeMark.addressDictionary!["ZIP"] as? NSString { 
      print(zip) 
     } 

     // Country 
     if let country = placeMark.addressDictionary!["Country"] as? NSString { 
      print(country) 
     } 

    }) 
+0

yessss !!! ... спасибо большое. – Arda

+0

, но информация о некоторых местах не существует. Ты знаешь почему? – Arda

Смежные вопросы