//跳转到第三方应用
[[UIApplication sharedApplication]canOpenURL:[NSURL URLWithString:@"iosamap://"]];
if ([[UIApplication sharedApplication]canOpenURL:[NSURL URLWithString:@"http://maps.apple.com"]]) {
MKMapItem*currentLocation = [MKMapItemmapItemForCurrentLocation];
CLGeocoder*geocoder = [[CLGeocoderalloc]init];
[geocodergeocodeAddressString:@"北京"completionHandler:^(NSArray *_Nullableplacemarks,NSError*_Nullableerror) {
CLPlacemark*endPlacemark = placemarks.lastObject;
MKPlacemark*endMKPlacemark = [[MKPlacemarkalloc]initWithPlacemark:endPlacemark];
MKMapItem*endMapItem = [[MKMapItemalloc]initWithPlacemark:endMKPlacemark];
[MKMapItem openMapsWithItems:@[endMapItem] launchOptions:@{
MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeDriving,
MKLaunchOptionsShowsTrafficKey:[NSNumber numberWithBool:YES]
}];
}];
}
#pragma mark- 经纬度定位跳转
- (void)pingguoMapWithWithEndLocationCoordinate:(CLLocationCoordinate2D )endLocationCoordinate{
MKMapItem *currentLoc = [MKMapItem mapItemForCurrentLocation];
MKMapItem *toLocation = [[MKMapItem alloc]initWithPlacemark:[[MKPlacemark alloc]initWithCoordinate:endLocationCoordinate addressDictionary:@{}]];
NSDictionary*dic =@{
MKLaunchOptionsDirectionsModeKey : MKLaunchOptionsDirectionsModeDriving,
// MKLaunchOptionsMapTypeKey : @(MKMapTypeStandard),
MKLaunchOptionsShowsTrafficKey : @(YES)
};
[MKMapItemopenMapsWithItems:@[currentLoc,toLocation]launchOptions:dic];
}
- (void)locationBtnAction{
CLLocationCoordinate2D endCoor =CLLocationCoordinate2DMake(self.location_lat, self.location_lng);
[self pingguoMapWithWithEndLocationCoordinate:endCoor];
网友评论