// 創(chuàng)建 coordinate
CLLocationCoordinate2D coordinate =
CLLocationCoordinate2DMake(latitude, longitude);
// 創(chuàng)建 MKPlacemark
MKPlacemark *placemark = [[MKPlacemark alloc]initWithCoordinate:coordinate
addressDictionary:nil];
// 創(chuàng)建 MKMapItem
MKMapItem *mapItem = [[MKMapItem alloc] initWithPlacemark:placemark];
mapItem.name = @"Target place";
// 跳轉至 Map App
[mapItem openInMapsWithLaunchOptions:nil];
// 或是使用 Class method 替代
// [MKMapItem openMapsWithItems:@[mapItem] launchOptions:nil];
NSString *address = @"403臺中市西區(qū)健行路1049號";
CLGeocoder *geocoder = [[CLGeocoder alloc]init];
void (^handler)(NSArray *geoMarks, NSError *error) = ^(NSArray *geoMarks, NSError *error){
CLPlacemark *geoMark = geoMarks.firstObject;
MKPlacemark *targetMark = [[MKPlacemark alloc]initWithPlacemark:geoMark];
MKMapItem *targetItem = [[MKMapItem alloc]initWithPlacemark:targetMark];
[targetItem openInMapsWithLaunchOptions:nil];
};
[geocoder geocodeAddressString:address completionHandler:handler];
/** 這裡以 User 目前位置跟 Target 位置做規(guī)劃 */
// 使用者目前位置
MKMapItem *currentLocationMapItem = [MKMapItem mapItemForCurrentLocation];
// Target 位置, 按照上兩個方式創(chuàng)建
MKMapItem *targetItem = ......
// 路徑方式, 這裡以開車做規(guī)劃
NSDictionary *launchOptions = @{MKLaunchOptionsDirectionsModeKey : MKLaunchOptionsDirectionsModeDriving};
// 跳轉至 Map App, 只能使用 Class method
[MKMapItem openMapsWithItems:@[currentLocationMapItem, targetItem]
launchOptions:launchOptions];
最后編輯于 :
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者