我目前正在开发一款具有 map View 的应用程序,该应用程序可以打开 Apple map 并发送经度和纬度作为起点和终点位置。因此,用户可以借助 Apple map 进行导航。我的问题是:是否可以让苹果 map 应用程序自动运行导航功能?就像现在一样,它会在开始位置和停止位置上使用正确的坐标和注释打开 Apple Maps 应用程序,但我必须单击导航功能才能让 Apple Maps 显示从开始到停止的导航路线。
这是从我自己的应用程序打开 Apple map 的代码:
// NAVIGATION ACTION SHEET
if (buttonIndex == 0) {
double toLatDouble = [to_lat doubleValue];
double toLongDouble = [to_long doubleValue];
CLLocationCoordinate2D location = CLLocationCoordinate2DMake(toLatDouble,toLongDouble);
// Apple Maps, using the MKMapItem class
MKPlacemark *placemark = [[MKPlacemark alloc] initWithCoordinate:location addressDictionary:nil];
MKMapItem *item = [[MKMapItem alloc] initWithPlacemark:placemark];
item.name = self.toLocation;
[item openInMapsWithLaunchOptions:nil];
}
else if (buttonIndex == 1){
double fromLatDouble = [from_lat doubleValue];
double fromLongDouble = [from_long doubleValue];
CLLocationCoordinate2D location = CLLocationCoordinate2DMake(fromLatDouble,fromLongDouble);
// Apple Maps, using the MKMapItem class
MKPlacemark *placemark = [[MKPlacemark alloc] initWithCoordinate:location addressDictionary:nil];
MKMapItem *item = [[MKMapItem alloc] initWithPlacemark:placemark];
item.name = self.toLocation;
[item openInMapsWithLaunchOptions:nil];
}else {
// Cancel
NSLog(@"User canceled navigation actionSheet");
}
最佳答案
如 MKMapItem
的文档中所述当你调用 openInMapsWithLaunchOptions
: 你也可以传递一些选项。其中之一激活导航模式。
例如,要开始行车路线,您应该这样写:
[item openInMapsWithLaunchOptions:@{MKLaunchOptionsDirectionsModeKey :MKLaunchOptionsDirectionsModeDriving}];
关于objective-c - 直接从应用程序运行 Apple map gps 导航,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18712630/