iOS6上的转弯功能

时间:2012-11-03 10:46:07

标签: ios mapkit

您好我正试图在iOS6上使用Mapkit获得2点之间的路线。想法是在地图上获取路线和叠加。但是获得Turn by tun的唯一方法是使用地图应用程序或使用URL启动地图应用程序。

可以在不关闭iOS6上的应用程序的情况下获得Turn by turn功能吗?

1 个答案:

答案 0 :(得分:0)

您可以使用Web视图进行此操作,并仅在UIWebView中打开Safari,现在只需为其添加导航栏即可导航到您的应用程序。

使用以下代码:

    MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } };
    region.center.latitude = getLatitude;
    region.center.longitude = getLongitude;

    MKCoordinateRegion currentRegion = { {0.0, 0.0 }, { 0.0, 0.0 } };
    currentRegion.center.latitude = currentLatitude;
    currentRegion.center.longitude = currentLongitude;
    region.span.longitudeDelta = 4.0f;
    region.span.latitudeDelta = 4.0f;
    currentRegion.span.longitudeDelta = 4.0f;
    currentRegion.span.latitudeDelta = 4.0f;

    CLLocationCoordinate2D start = { currentRegion.center.latitude, currentRegion.center.longitude };
    CLLocationCoordinate2D destination = { region.center.latitude, region.center.longitude };


    NSString *googleMapsURLString = [NSString stringWithFormat:@"http://maps.google.com/?saddr=%1.6f,%1.6f&daddr=%1.6f,%1.6f",start.latitude, start.longitude, destination.latitude, destination.longitude];

    NSURL *url=[NSURL URLWithString:googleMapsURLString];
    NSURLRequest *requestObj=[NSURLRequest requestWithURL:url];
    [webView loadRequest:requestObj];