我正在尝试将我的用户定向到iOS 6原生地图,以获得从他们的当前位置到纬度和经度位置的方向,如下所示:
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];我已将模拟器设置为我的纬度和经度。这里我的代码出了什么问题?
发布于 2013-01-13 18:47:33
代码很好,只要有一条可能的路线,我就能正常工作。
当可以给出currentLocation和目的地之间的方向时起作用。如果currentLocation在美国,地图就会失败,因为它不能从德国导航到美国。但如果currentLocation也在欧洲,地图应用程序就可以正常工作:)
//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];https://stackoverflow.com/questions/14302369
复制相似问题