您的位置:首页 > 其它

打开苹果自带地图进行导航

2013-06-29 02:31 375 查看
float latitude= [[self.data
objectForKey:@"y"]
floatValue];
float longitude= [[self.data
objectForKey:@"x"]
floatValue];

if (SYSTEM_VERSION_LESS_THAN(@"6.0")) {
// ios6以下,调用google map
NSString *urlString = [[NSString
alloc] initWithFormat:@"http://maps.google.com/maps?q=loc:%f,%f",latitude,longitude];
NSURL *aURL = [NSURL
URLWithString:urlString];
[[UIApplication
sharedApplication] openURL:aURL];
} else {
// 直接调用ios自己带的apple map
CLLocationCoordinate2D to;
to.latitude = latitude;
to.longitude = longitude;

MKMapItem *currentLocation = [MKMapItem
mapItemForCurrentLocation];
MKMapItem *toLocation = [[MKMapItem
alloc] initWithPlacemark:[[[MKPlacemark
alloc] initWithCoordinate:to
addressDictionary:nil]
autorelease]];
toLocation.name =
@"Destination";
[MKMapItem
openMapsWithItems:[NSArray
arrayWithObjects:currentLocation, toLocation,
nil] launchOptions:[NSDictionary
dictionaryWithObjects:[NSArray
arrayWithObjects:MKLaunchOptionsDirectionsModeDriving, [NSNumber
numberWithBool:YES],
nil] forKeys:[NSArray
arrayWithObjects:MKLaunchOptionsDirectionsModeKey,
MKLaunchOptionsShowsTrafficKey, nil]]];
[toLocation release];
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: