如何使用新的iOS 6.0地图在两个地址之间路由?(How to route between two addresses using the new iOS 6.0 maps?)

系统教程 行业动态 更新时间:2024-06-14 16:59:47
如何使用新的iOS 6.0地图在两个地址之间路由?(How to route between two addresses using the new iOS 6.0 maps?)

我正在使用iOS 6.0 SDK,我想在Apple的新iOS 6.0地图之间路由两个不同的地址(不是纬度和经度)。 我也想表明这些迹象。

我怎样才能做到这一点?

I'm using the iOS 6.0 SDK and I would like to route between two different addresses (not latitude and longitude) with Apple's new iOS 6.0 maps. I would like to show the indications too.

How can I do this?

最满意答案

上周我研究了这样做,并没有想办法做到这一点。 您似乎可以给出一个目的地,并且您可以给它提供的不仅仅是坐标,但它始终假定您的起始位置是当前位置。 当您目前不在起始位置时计划旅行时,这是有限的。 (但也许我只是没看到它是如何完成的,我希望有人可以纠正我,如果这是真的。)

前一段时间我查看了iOS 6的路由选项,并在此收集结果......

您如何为地图上的点之间的路线提供路线? 丢失的是什么?

您仍然可能无法使用所需的确切路由打开Apple Maps,但也许您可以在自己的实例MKMapView上使用叠加和注释绘制路径。 这可能是你现在能做的最好的事情。

下面是我用于路由到某个位置并至少为目标提供标签而不是仅将其留给坐标的代码。 我发现只是给目的地一个带有完整地址详细信息的标签是行不通的,所以我只提供一个值。

if (flag != DirectionsFlag_PublicTransit && itemClass && [itemClass respondsToSelector:@selector(openMapsWithItems:launchOptions:)]) { NSDictionary *address = @{ (NSString *)kABPersonAddressStreetKey : location.title }; MKPlacemark *destinationPlacemark = [[MKPlacemark alloc] initWithCoordinate:location.coordinate addressDictionary:address]; MKMapItem *destinationMapItem = [[MKMapItem alloc] initWithPlacemark:destinationPlacemark]; if (flag == DirectionsFlag_Driving) { [destinationMapItem openInMapsWithLaunchOptions:@{MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeDriving}]; } else if (flag == DirectionsFlag_Walking) { [destinationMapItem openInMapsWithLaunchOptions:@{MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeWalking}]; } }

此代码专门不处理公共交通路线,因为Apple Maps不这样做。 我改为使用之前使用的URL打开谷歌地图,现在可以打开这些方向的Safari。 旗帜是驾驶,步行或公共交通的枚举值。 该位置是一个模型,其中包含各种细节,包括标题和坐标。

I looked into do doing this last week and did not figure out a way to do it. It appears that you can give a destination, and you can sort of give it more than just coordinates, but it always assumes your starting position is the current location. That is limiting when you may be planning a trip while you are not currently at the starting location. (But perhaps I am just not seeing how it is done and I hope someone can correct me if that is true.)

A while back I looked into routing options for iOS 6 and gathered the results here...

How would you providing routing for directions between points on a map? What are the missing pieces?

You still may not be able to open up Apple Maps with the exact routing that you want, but perhaps you can draw the route with overlays and annotations on your own instance MKMapView. That may be the best you can do for now.

Below is the code that I used to route to a location and provide at least a label for the destination instead of leaving it to only coordinates. I found that simply giving the destination a label with the full address details would not work, so I just provide that one value.

if (flag != DirectionsFlag_PublicTransit && itemClass && [itemClass respondsToSelector:@selector(openMapsWithItems:launchOptions:)]) { NSDictionary *address = @{ (NSString *)kABPersonAddressStreetKey : location.title }; MKPlacemark *destinationPlacemark = [[MKPlacemark alloc] initWithCoordinate:location.coordinate addressDictionary:address]; MKMapItem *destinationMapItem = [[MKMapItem alloc] initWithPlacemark:destinationPlacemark]; if (flag == DirectionsFlag_Driving) { [destinationMapItem openInMapsWithLaunchOptions:@{MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeDriving}]; } else if (flag == DirectionsFlag_Walking) { [destinationMapItem openInMapsWithLaunchOptions:@{MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeWalking}]; } }

This code specifically does not handle Public Transit directions since Apple Maps does not do that. I instead have it open up Google Maps with the URL that I was using previously which now opens up Safari for those directions. The flag is an enum value of Driving, Walking or Public Transit. The location is a model which contains various details including title and coordinates.

更多推荐

本文发布于:2023-04-17 09:06:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/129a7822379cbf501f44f5023746ec6c.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:路由   如何使用   两个   地址   地图

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!