2017-04-05 47 views
1

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

任何想法?它实际上可能吗?

+0

有人,有人吗? – Fattie

+0

我总是惊讶MapKit是如此惊人,而且用得很少。 – Fattie

回答

1

我认为openInMaps仅限于the five possible launch options。但是,我想知道是否可以让Apple Maps以原始方式打开,openURL和maps.apple.com/maps,如this SO question中所示。不过,对于最新的iOS版本,似乎您还需要在“URL类型... URL计划”或“LSApplicationQueriesSchemes”下注册您在info.plist中使用的URL。您可能能够将注释作为参数传递给URL。

+0

只有五个启动选项是一个很好的观点。但是请注意,**你发送的是一个'MKPlacemark' ** - 所以,可以将一个MKPointAnnotation附加到那个?** Tricky! – Fattie

+0

我想这是最接近的答案!谢谢,我打勾了! – Fattie