【问题标题】:Turn by turn within MKMapView on iOS 6在 iOS 6 上的 MKMapView 中轮流转
【发布时间】:2012-12-08 12:46:25
【问题描述】:

我想知道是否可以在 iOS 6 上的 MKMapView 中创建导航路线,而不是打开内置的地图应用程序?
我用谷歌搜索但没有找到任何答案。

这是我现在使用的代码(打开内置地图应用):

-(IBAction) navigation
{
    if (SYSTEM_VERSION_LESS_THAN(@"6.0"))
    {
        NSString *destinationString = @"Afek, Israel";
        NSString *url = [NSString stringWithFormat: @"http://maps.google.com/maps?saddr=%f,%f&daddr=%@",wedMapView.userLocation.coordinate.latitude,wedMapView.userLocation.coordinate.longitude, destinationString];
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
    }

    else
    {
        Class mapItemClass = [MKMapItem class];
        if (mapItemClass && [mapItemClass respondsToSelector:@selector(openMapsWithItems:launchOptions:)])
        {
            double latitude = 32.83431728836292;
            double longitude = 35.128666162490845;
            MKPlacemark *placemark = [[[MKPlacemark alloc] initWithCoordinate:CLLocationCoordinate2DMake(latitude, longitude) addressDictionary:nil] autorelease];
            //[mapItem setName:@"Name of your location"];

            // Create a map item for the geocoded address to pass to Maps app
            MKMapItem *mapItem = [[MKMapItem alloc] initWithPlacemark:placemark];
            [mapItem setName:@"שמורתה, קיבוץ אפק"];

            // Set the directions mode to "Driving"
            // Can use MKLaunchOptionsDirectionsModeWalking instead
            NSDictionary *launchOptions = @{MKLaunchOptionsDirectionsModeKey : MKLaunchOptionsDirectionsModeDriving};

            // Get the "Current User Location" MKMapItem
            MKMapItem *currentLocationMapItem = [MKMapItem mapItemForCurrentLocation];

            // Pass the current location and destination map items to the Maps app
            // Set the direction mode in the launchOptions dictionary
            [MKMapItem openMapsWithItems:@[currentLocationMapItem, mapItem] launchOptions:launchOptions];
        };
    }
}  

这是我拥有的 MKMapView,当我按下蓝色地图按钮(Waze 按钮上方)时,我想通过转弯路线进行转弯:

感谢您的帮助。

【问题讨论】:

    标签: iphone xcode navigation routes mkmapview


    【解决方案1】:

    iOS 6 不为应用程序提供方向,它依赖于内置的地图应用程序来做到这一点。因此,如果您想在您的应用程序中显示路线,您需要找到用于计算路线的服务。你不能使用谷歌,因为他们只允许你在他们的地图上使用他们的数据,而不是在苹果的地图上。您可以查看 CloudMade 和 OpenStreetMap,但您必须为此放弃使用 iOS 6 的地图。它们带有开放式 UI 组件。

    【讨论】:

    • 得到我的答案...谢谢克雷格!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-09-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-19
    • 1970-01-01
    相关资源
    最近更新 更多