지도보기가 있으며 사용자가 누른 위치에 핀을 놓을 수있는 방법을 추가했습니다. 콜 아웃은 이미지에 표시된 위치의 주소를 보여줍니다. 지도 키트로 상점 이름/레스토랑 이름을 얻을 수 있습니까? (신속)
screenshot of my mapview with annotation pin and callout view.
그리고 내 코드는 다음과 같습니다 :func onTapGestureRecognized(sender: UILongPressGestureRecognizer) {
self.mapView.removeAnnotations(mapView.annotations)
let location = tapRecognizer.location(in: mapView)
let coordinate = mapView.convert(location,toCoordinateFrom: mapView)
let getLat: CLLocationDegrees = coordinate.latitude
let getLon: CLLocationDegrees = coordinate.longitude
let theLocation: CLLocation = CLLocation(latitude: getLat, longitude: getLon)
let geoCoder = CLGeocoder()
geoCoder.reverseGeocodeLocation(theLocation, completionHandler: { (placemarks, error) -> Void in
// Place details
var placeMark: CLPlacemark!
placeMark = placemarks?[0]
var theLocationName = ""
var theStreetNumber = ""
var theStreet = ""
var theCity = ""
var theZip = ""
var theCountry = ""
// Address dictionary
print(placeMark.addressDictionary as Any)
// Location name
if let locationName = placeMark.name{
theLocationName = locationName
}
if let streetNumber = placeMark.subThoroughfare{
theStreetNumber = streetNumber
}
// Street address
if let street = placeMark.thoroughfare {
theStreet = street
}
// City
if let city = placeMark.locality {
theCity = city
}
// Zip code
if let zip = placeMark.postalCode{
theZip = zip
}
// Country
if let country = placeMark.isoCountryCode{
theCountry = country
}
let annotation = MKPointAnnotation()
annotation.title = theLocationName
annotation.subtitle = theStreetNumber + " " + theStreet + ", " + theCity + ", " + theCountry + ", " + theZip
if let location = placeMark.location {
annotation.coordinate = location.coordinate
// Display the annotation
self.mapView.showAnnotations([annotation], animated: true)
}
})
}
당신이 볼 수 있듯이, 내가 선을 (호출하여 위치 이름을 얻을 때 (((locationName = 위치 표시를 할 경우. 이름)))), 나는 단지 레스토랑 이름 대신에 "5197 Yonge St"라는 주소를 얻을 수있다 : "Pho 88 Restaurant".
내가 어디에서 잘못했는지 누가 알 수 있습니까? 또는 단순히 달성 될 수 없는가? 감사!
아마도 **지도 ** 위치가 그거일까요? ** 비즈니스 ** 위치가 아닌가요? – dfd
코드가 다른 위치에서 완벽하게 작동하지만 다른 위치에서 시도하십시오. –
@ArpitDongre 예 다른 장소에서 시도한 적이 있습니다. 장소 또는 플라자 (예 : 도심 노스 요크, 멜 이스트만 스퀘어)의 이름을 표시하지만 식당 이름이나 상점 이름이 없습니다 (회사 이름) –