얻으이 같은 주소 : -
func getAddressForLatLng(latitude: CLLocationDegrees, longitude: CLLocationDegrees, completionBlock : ((addrs : String)->Void)) {
let url = NSURL(string: "\(baseUrl)latlng=\(latitude),\(longitude)&key=\(serverKey)")
print(url)
let data = NSData(contentsOfURL: url!)
let json = try! NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions.AllowFragments) as! NSDictionary
if let result = json["results"] as? NSArray {
if let address = result[0]["address_components"] as? NSArray {
let number = address[0]["short_name"] as! String
let street = address[1]["short_name"] as! String
let city = address[2]["short_name"] as! String
let state = address[4]["short_name"] as! String
let zip = address[6]["short_name"] as! String
print("\(number) \(street), \(city), \(state) \(zip)")
completionBlock(addrs: "\(number) \(street), \(city), \(state) \(zip)")
}
}
}
업데이트합니다 didLongPressAtCoordinate 기능 : -
func mapView(mapView: GMSMapView!, didLongPressAtCoordinate coordinate: CLLocationCoordinate2D) {
let marker = GMSMarker()
marker.position = CLLocationCoordinate2D(latitude: coordinate.latitude, longitude: coordinate.longitude)
self.googleMapsView.clear()
self.googleMapsView.myLocationEnabled = false
marker.map = self.googleMapsView
getAddressForLatLng(coordinate.latitude, longitude: coordinate.longitude) { (addrs) in
marker.title = addrs
marker.snippet = "\(coordinate.latitude),\(coordinate.longitude)"
}
}
마음이 - base을 그리고 serverKey 귀하의 Google 콘솔 base을하고 있습니다 serverKey
안녕하세요, scbas1000, 스택 오버플로에 오신 것을 환영합니다. 귀하의 질문은 매우 모호하며 답할 기회가 거의 없습니다. [묻는 방법] 가이드 (http://stackoverflow.com/help/how-to-ask)를 방문하십시오. – Alexander
주목 해 주셔서 고맙습니다. 지금 편집 해주세요. – scbas1000
@ scbas1000 아니요, 질문은 여전히 매우 모호하며 지금까지 가지고있는 것을 보여주는 코드를 게시하지 않았습니다. 당신이 가지고있는 코드를 게시하고, 분당으로 무엇을했는지, 무엇을 달성하려고하는지 (예는 도움이 될 것인가)에 대해 명확히 논의한 다음, 오류/문제점을 나열하십시오. –