【问题标题】:get direction functionality on map app iOS在地图应用 iOS 上获取方向功能
【发布时间】:2017-05-15 20:53:08
【问题描述】:

我想在 iOS 默认地图应用中的两个位置之间实现获取方向功能,我已经尝试过了

Class itemClass = [MKMapItem class];
if (itemClass && [itemClass respondsToSelector:@selector(openMapsWithItems:launchOptions:)]) {
    // Use iOS 6 maps
    NSString *latString = @"23.0300";
    NSString *longString = @"72.5800";

    CLLocationCoordinate2D  ctrpoint;
    ctrpoint.latitude = [latString doubleValue];
    ctrpoint.longitude = [longString doubleValue];

    MKPlacemark *placemark2 = [[MKPlacemark alloc] initWithCoordinate:ctrpoint addressDictionary:nil];
    MKMapItem *mapItem = [[MKMapItem alloc] initWithPlacemark:placemark2];
    [mapItem openInMapsWithLaunchOptions:nil];
}

但它显示的方向错误如下:

我什至打开了地图应用,找到了我当前的位置,在地图上添加了一个离我最近的位置最近的图钉,但仍然无法获取方向。

还有“简而言之,即使在本机应用程序中,Get Direction 也不能完全正常工作”任何人都可以帮助我实现这一目标吗?

【问题讨论】:

  • 你在哪里?
  • 在印度古吉拉特邦拉杰科特。我现在的纬度是:22.3000, 70.7833
  • 您可以在常规地图应用中获取路线吗?
  • 没有人我没有!!! :(

标签: ios iphone mkmapview mapkit


【解决方案1】:

Apple 地图不支持印度的路线。

如果在手机上可用,您可以使用 Google 地图获取路线。 如果 Google 地图应用程序不可用,请使用 Apple 地图。

以下代码块可能会有所帮助。

    NSURL *appUrl;

    //Is Google Maps App Installed ?
   if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"comgooglemaps://"]]) {

        // Use Google Maps App to get Directions
       appUrl = [NSURL URLWithString:[NSString stringWithFormat:@"comgooglemaps://?daddr=%f,%f&saddr=%f,%f",
                            destLocation.coordinate.latitude, destLocation.coordinate.longitude,
                            _currentLocation.coordinate.latitude,_currentLocation.coordinate.longitude]];
    }

    // Google Maps not Installed
    else {

        // Use Apple Maps App to get Directions
        appUrl = [NSURL URLWithString:[NSString stringWithFormat:@"http://maps.apple.com/?daddr=%f,%f&saddr=%f,%f",
                           destLocation.coordinate.latitude, destLocation.coordinate.longitude,
                           _currentLocation.coordinate.latitude,_currentLocation.coordinate.longitude]];
    }

    [[UIApplication sharedApplication] openURL:appUrl];

【讨论】:

    【解决方案2】:

    据此Apple feature availability 称,印度不支持路线。

    根据this post,iOS 6 似乎也是如此。

    【讨论】:

    • 谢谢你是对的,因为当我改变了我的模拟器的纬度和目标位置时它工作得非常好......虽然它在我的国家工作得非常糟糕:(
    • 嘿,丹,它说 ios7 不支持功能,但我使用的是 ios6,但为什么仍然不支持?
    • 编辑了我的答案。我同意,确实很糟糕!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-16
    • 2020-10-21
    相关资源
    最近更新 更多