我想在我的应用程序中创建一个功能,通过它我可以从当前位置绘制一条线到所需的浮点值坐标。请建议我做同样的最好的有效方法。
问问题
127 次
1 回答
0
我对所有 ios 的问题都有答案,如下
// 使用地理编码器显示方向... * - (void)showDirection:(id)sender
{
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]];
}
}
于 2013-01-04T09:43:12.577 回答