美文网首页
苹果自带地图导航

苹果自带地图导航

作者: new一个person | 来源:发表于2019-10-22 16:01 被阅读0次

 //跳转到第三方应用

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

相关文章

网友评论

      本文标题:苹果自带地图导航

      本文链接:https://www.haomeiwen.com/subject/lxgqvctx.html