將註釋添加到您的應用內的MapKit視圖中很容易。如何獲取Apple Maps App(不是MapKit)添加註釋?
theMap: MKMapView!
let pa = MKPointAnnotation()
pa.title = "title!!" etc
theMap.addAnnotation(pa)
但是,您如何使地圖應用程序添加註釋?
這裏有究竟該如何打開地圖應用到某個地址..
func appleMapApp() {
quickAddressText = "123 Smith St 90210"
let bottomText = "This shows at BOTTOM Of Maps App screen."
let g = CLGeocoder()
g.geocodeAddressString(quickAddressText) { placemarks, error in
if let found = placemarks?.first, let lok = found.location {
let p = MKPlacemark(coordinate: lok.coordinate, addressDictionary: nil)
let mapItem = MKMapItem(placemark: p)
mapItem.name = bottomText
mapItem.openInMaps(launchOptions: showing(location: lok))
}
}
}
// convenient function...
func showing(location: CLLocation, meters m: CLLocationDistance = 1000)->[String : Any]? {
let cr = MKCoordinateRegionMakeWithDistance(location.coordinate, m,m)
let options = [
MKLaunchOptionsMapCenterKey: NSValue(mkCoordinate: cr.center),
MKLaunchOptionsMapSpanKey: NSValue(mkCoordinateSpan: cr.span)
]
return options
}
這是偉大的 - 但如何赫克你在MKPointAnnotation
實際的地圖應用程序傳遞?
(再次 - 它很容易在自己的應用程序中的地圖視圖中添加MKPointAnnotation。)
任何想法?它實際上可能嗎?
有人,有人嗎? – Fattie
我總是驚訝MapKit是如此驚人,而且用得很少。 – Fattie