问题
It's quite easy to add an annotation to a MapKit view which is inside your app.
theMap: MKMapView!
let pa = MKPointAnnotation()
pa.title = "title!!" etc
theMap.addAnnotation(pa)
But how the heck do you make the Maps App add an annotation??
Here's exactly how to open the Maps App to a certain address..
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
}
That's great - but how the heck do you pass in a MKPointAnnotation
to the actual Maps app??
(Again - it's easy to add a MKPointAnnotation on a map view inside your own app.)
Any ideas? Is it actually possible??
回答1:
I think openInMaps limits you only to the five possible launch options. But I wonder if you could get Apple Maps to open in the original way, openURL and maps.apple.com/maps, as shown in this SO question. With the newest iOS versions, though, it seems you also need to register the URL you're using in your info.plist under "URL Types ... URL Schemes" or "LSApplicationQueriesSchemes". You might be able to pass an annotation as a parameter with the URL.
来源:https://stackoverflow.com/questions/43234808/how-to-get-apple-maps-app-not-mapkit-to-add-an-annotation