我想知道是否可以在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];
};
}
}
当我按下蓝色地图按钮(在Waze按钮上方)时,这是我想转弯的MKMapView:
感谢您的帮助。
答案 0 :(得分:1)
iOS 6不向应用提供路线,它依赖于内置的地图应用来实现这一目标。因此,如果您想在应用中显示路线,则需要找到计算路线的服务。您不能使用Google,因为它们只允许您在地图上使用他们的数据,而不是Apple的数据。您可以查看CloudMade和OpenStreetMap,但是您必须放弃使用iOS 6的地图。它们带有开放的UI组件。