Ich habe eine Mapview und ich habe eine Methode hinzugefügt, um einen Pin an der Stelle zu hinterlassen, wo der Benutzer gedrückt hat. Das Callout zeigt die Adresse des Ortes, wie auf dem Bild gezeigt.Kann ich einen Ladennamen/Restaurantnamen mit mapkit bekommen? (Swift)
screenshot of my mapview with annotation pin and callout view.
Und mein Code ist wie folgt:
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)
}
})
}
Wie Sie sehen können, wenn ich versuche, durch den Aufruf der Linie, die die Ortsnamen zu erhalten ((((wenn location = Ortsmarkierungs lassen. Name)))), kann ich nur die Adresse: "5197 Yonge St", anstelle des Restaurantnamens: "Pho 88 Restaurant".
Kann mir jemand sagen, wo ich falsch gemacht habe? oder ist es einfach nicht zu erreichen? Vielen Dank!
Vielleicht, weil ein ** map ** Standort genau das ist? Kein ** Business ** Standort? – dfd
Ihr Code funktioniert perfekt mit einem anderen Ort, versuchen Sie es für einen anderen Ort. –
@ArpitDongre Ja, ich habe es mit anderen Orten versucht, es zeigt manchmal den Namen eines Ortes oder einer Plaza (zB City Centre North York, Mel Eastman Square), aber nie einen Restaurantnamen oder einen Geschäftsnamen (Firmennamen) –