【问题标题】:Run Apple map gps navigation directly from app直接从应用程序运行 Apple 地图 gps 导航
【发布时间】:2013-09-10 07:09:43
【问题描述】:

我目前正在开发一个带有地图视图的应用程序,该应用程序可以打开 Apple 地图并发送经度和纬度,因此是开始和停止位置。因此,用户可以在 Apple 地图的帮助下进行导航。我的问题是:是否可以让 Apple Maps 应用程序自动运行导航功能?就像现在一样,它会打开 Apple Maps 应用程序,并在开始位置和停止位置上有正确的坐标和注释,但我必须单击导航功能才能让 Apple Maps 显示从开始到停止的导航路线。

这是从我自己的应用程序中打开 Apple 地图的代码:

// 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");
        }

【问题讨论】:

    标签: objective-c navigation gps apple-maps


    【解决方案1】:

    正如MKMapItem 的文档中所述,当您调用openInMapsWithLaunchOptions 时:您还可以传递一些选项。其中之一激活导航模式。

    例如,要开始行车路线,您应该写:

    [item openInMapsWithLaunchOptions:@{MKLaunchOptionsDirectionsModeKey :MKLaunchOptionsDirectionsModeDriving}];
    

    【讨论】:

      猜你喜欢
      • 2021-01-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-01
      • 2018-07-20
      • 1970-01-01
      • 2021-12-18
      • 1970-01-01
      相关资源
      最近更新 更多