objective-c - 直接从应用程序运行 Apple map gps 导航

标签 objective-c navigation gps apple-maps

我目前正在开发一款具有 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/

相关文章:

java - 在android中使用GPS计算累计距离

android - Google FusedLocationApi API 调用 onConnectionSuspended 的时间太多,我无法获取 GPS 位置

ios - 使用仪器了解 Objective-C 中的保留计数(泄漏)

objective-c - UIPageViewController:定位页面指示器

javascript - 在 AngularJS 中调整导航指令

html - 在 CSS 中的每个元素后添加一个符号

ios - 如何在 Xamarin iOS 应用程序中启用位置服务

ios - 允许 VOIP iOS 应用程序在退出后台模式时接听电话

iphone - 如何链接 UIAlertView 中的 otherButtonTitles 以启动 Tweeter Composer ?

html - 我的悬停下拉菜单隐藏在内容后面(图片)