苹果自带地图导航

2019-10-22  本文已影响0人  new一个person

 //跳转到第三方应用

    [[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];

上一篇 下一篇

猜你喜欢

热点阅读