将注释添加到您的应用内的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