首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >iOS 6地图-找不到方向

iOS 6地图-找不到方向
EN

Stack Overflow用户
提问于 2013-01-13 17:48:55
回答 1查看 653关注 0票数 0

我正在尝试将我的用户定向到iOS 6原生地图,以获得从他们的当前位置到纬度和经度位置的方向,如下所示:

代码语言:javascript
复制
MKPlacemark *placemark = [[MKPlacemark alloc] initWithCoordinate:placeLocation addressDictionary:nil];
MKMapItem *destination = [[MKMapItem alloc] initWithPlacemark:placemark];
MKMapItem *currentLocation = [MKMapItem mapItemForCurrentLocation];
NSArray *mapItems = @[destination, currentLocation];
NSDictionary *options = @{MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeDriving, MKLaunchOptionsMapTypeKey: [NSNumber numberWithInteger:MKMapTypeStandard], MKLaunchOptionsShowsTrafficKey:@YES};
[MKMapItem openMapsWithItems:mapItems launchOptions:options];

我已将模拟器设置为我的纬度和经度。这里我的代码出了什么问题?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-01-13 18:47:33

代码很好,只要有一条可能的路线,我就能正常工作。

当可以给出currentLocation和目的地之间的方向时起作用。如果currentLocation在美国,地图就会失败,因为它不能从德国导航到美国。但如果currentLocation也在欧洲,地图应用程序就可以正常工作:)

代码语言:javascript
复制
//placeMarkCoord fixed to germany
MKPlacemark *placemark = [[MKPlacemark alloc] initWithCoordinate:CLLocationCoordinate2DMake(51.0, 10.0) addressDictionary:nil];
MKMapItem *destination = [[MKMapItem alloc] initWithPlacemark:placemark];

//currentLocation must be reachable from destination!
//MKMapItem *currentLocation = [MKMapItem mapItemForCurrentLocation];
placemark = [[MKPlacemark alloc] initWithCoordinate:CLLocationCoordinate2DMake(51.0, 11.0) addressDictionary:nil];
MKMapItem *currentLocation = [[MKMapItem alloc] initWithPlacemark:placemark];

NSArray *mapItems = @[destination, currentLocation];
NSDictionary *options = @{MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeDriving, MKLaunchOptionsMapTypeKey: [NSNumber numberWithInteger:MKMapTypeStandard], MKLaunchOptionsShowsTrafficKey:@YES};
[MKMapItem openMapsWithItems:mapItems launchOptions:options];
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14302369

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档