如何使Apple Maps App(而非MapKit)添加注释? [英] How to get Apple Maps App (not MapKit) to add an annotation?

查看:83
本文介绍了如何使Apple Maps App(而非MapKit)添加注释?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

注释添加到位于应用内 的MapKit视图中是很容易的.

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)

但是您如何使Google Maps App添加注释?

But how the heck do you make the Maps App add an annotation??

这是将Maps App打开到特定地址的确切方法.

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
}

那太好了-但是您如何将MKPointAnnotation传递给实际的Maps应用?

That's great - but how the heck do you pass in a MKPointAnnotation to the actual Maps app??

(再次-您可以在自己的应用内的地图视图上轻松添加MKPointAnnotation.)

(Again - it's easy to add a MKPointAnnotation on a map view inside your own app.)

有什么想法吗?真的有可能吗?

Any ideas? Is it actually possible??

推荐答案

我认为openInMaps仅将您限制为这个SO问题.但是,使用最新的iOS版本,您似乎还需要在info.plist中的"URL Types ... URL Schemes"或"LSApplicationQueriesSchemes"下注册要使用的URL.您也许可以将注释作为参数传递给URL.

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.

这篇关于如何使Apple Maps App(而非MapKit)添加注释?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆