2016-08-16 12 views
1

iOSのMapkitのデフォルトのロケーションポイントからロケーションの名前を取得するにはどうすればよいですか?私はそれ(ex.Swissホテル)をクリックすると、スウィフトに名を取得したいデフォルトアノテーションからロケーション名を取得する方法iOSのMapkit

enter image description here

+0

に対処するために、緯度と長い変換などの触れた場所にによる座標は、あなたがAnbu.Karthik @あなたの試したコード –

+0

を表示することができます取得これまでのコードはありません。mapviewを持つviewcontrollerだけです。私はカスタム注釈を作成することができますが、MapViewの現在の場所を使用したいと考えています – Arda

答えて

3

ステップ-1

マップ上のジェスチャーを追加

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

ステップ-2

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

関連する問題