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

查看:130
本文介绍了如何使用新的iOS 6.0地图在两个地址之间路由?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用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.

我该怎么做?

推荐答案

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

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.)

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

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

您如何为地图上各点之间的路线提供路线?丢失的内容有哪些?

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

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}];
    }
}

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

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.

这篇关于如何使用新的iOS 6.0地图在两个地址之间路由?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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