Ios 显示从当前点到从阵列中获取的所需点的直线路线的步骤
我想在我的应用程序中创建一个功能,通过该功能,我可以从当前位置到所需坐标(即浮点值)绘制一条线。请向我推荐最有效的方法。我已经得到了所有ios问题的答案,如下所示 //要使用地理编码器显示方向…* -(无效)显示方向:(id)发件人Ios 显示从当前点到从阵列中获取的所需点的直线路线的步骤,ios,mkmapview,Ios,Mkmapview,我想在我的应用程序中创建一个功能,通过该功能,我可以从当前位置到所需坐标(即浮点值)绘制一条线。请向我推荐最有效的方法。我已经得到了所有ios问题的答案,如下所示 //要使用地理编码器显示方向…* -(无效)显示方向:(id)发件人 { NSString *deviceVersion = [[UIDevice currentDevice] systemVersion]; NSLog(@"My Device version is :%@ ",deviceVersion);
{
NSString *deviceVersion = [[UIDevice currentDevice] systemVersion];
NSLog(@"My Device version is :%@ ",deviceVersion);
//********* For ios 6 supporting devices *********
if ([deviceVersion isEqualToString:@"6.0"])
{
Class itemClass = [MKMapItem class];
if (itemClass && [itemClass respondsToSelector:@selector(openMapsWithItems:launchOptions:)]) {
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
CLLocation *newLocation = [[CLLocation alloc]initWithLatitude:getLatitude
longitude:getLongitude];
[geocoder reverseGeocodeLocation:newLocation
completionHandler:^(NSArray *placemarks, NSError *error) {
MKPlacemark *placeMark = [[MKPlacemark alloc] initWithPlacemark:[placemarks objectAtIndex:0]];
MKMapItem *mapItem = [[MKMapItem alloc]initWithPlacemark:placeMark];
MKMapItem *mapItem2 = [MKMapItem mapItemForCurrentLocation];
NSArray *mapItems = @[mapItem, mapItem2];
NSDictionary *options = @{
MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeDriving,
MKLaunchOptionsMapTypeKey:
[NSNumber numberWithInteger:MKMapTypeStandard],
MKLaunchOptionsShowsTrafficKey:@YES
};
[MKMapItem openMapsWithItems:mapItems launchOptions:options];
} ];
}
else
{
UIAlertView *errorAlert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Failed to Get Your Location"delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[errorAlert show];
}
}
//********* For other ios supporting devices *********
else {
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];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:googleMapsURLString]];
}
}