在地图应用iOS上获取方向功能

D-e*_*per 3 iphone mapkit mkmapview ios

我想在iOS默认Map App中的两个位置之间实现get direction功能,我试过这个

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];
}
Run Code Online (Sandbox Code Playgroud)

但它显示方向错误如下:

获取方向错误

我甚至打开了地图应用程序,找到了我当前的位置,在离我所在位置最近的地图上添加了一个图钉,并且获取方向仍然无效.

此外,"总之,即使在本机应用程序中,Get Direction也无法正常工作"任何人都可以帮助我实现这一目标吗?

小智 7

Apple Maps不支持印度的路线.

您可以使用谷歌地图获取路线,如果它在手机上可用.如果谷歌地图应用程序无法使用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];
Run Code Online (Sandbox Code Playgroud)