iOS一次跳转到第三方地图导航小记

要点1:添加http 白名单 并判断app是否安装

App Transport Security Settings

      Allow Arbitrary Loads

LSApplicationQueriesSchemes

      Item0 baidumap

      Item1 iosamap

要点2:app调起

if([[UIApplicationsharedApplication]canOpenURL:[NSURLURLWithString:@"baidumap://map/"]]){}

if([[UIApplicationsharedApplication]canOpenURL:[NSURLURLWithString:@"iosamap://"]]){}

NSString*urlString = [[NSStringstringWithFormat:@"baidumap://map/direction?origin=latlng:%f,%f|name:我的位置&destination=latlng:%f,%f|name:终点&mode=driving", startP.x, startP.y, newEndP.x, newEndP.y]stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] ;

NSString*urlString = [[NSStringstringWithFormat:@"iosamap://navi?sourceApplication=%@&backScheme=%@&poiname=%@&poiid=%@&lat=%f&lon=%f&dev=0&style=2",@"chaojimali",@"chaojimali",nil,nil, endP.x, endP.y]stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

[[UIApplicationsharedApplication]openURL:[NSURLURLWithString:urlString]];

要点3:火星坐标和百度坐标转换

//百度转火星坐标

+ (CLLocationCoordinate2D)bdToGGEncrypt:(CLLocationCoordinate2D)coord

{

      doublex = coord.longitude-0.0065, y = coord.latitude-0.006;

      doublez =sqrt(x * x + y * y) -0.00002*sin(y *M_PI);

      doubletheta =atan2(y, x) -0.000003*cos(x *M_PI);

      CLLocationCoordinate2DtransformLocation ;

      transformLocation.longitude= z *cos(theta);

      transformLocation.latitude= z *sin(theta);

      returntransformLocation;

}

//火星坐标转百度坐标

+ (CLLocationCoordinate2D)ggToBDEncrypt:(CLLocationCoordinate2D)coord

{

      doublex = coord.longitude, y = coord.latitude;

      doublez =sqrt(x * x + y * y) +0.00002*sin(y *M_PI);

      doubletheta =atan2(y, x) +0.000003*cos(x *M_PI);

      CLLocationCoordinate2DtransformLocation ;

      transformLocation.longitude= z *cos(theta) +0.0065;

      transformLocation.latitude= z *sin(theta) +0.006;

      returntransformLocation;

}

坑点:因为原始的坐标是腾讯地图,腾讯、谷歌、高德统一用的火星,而百度用的自己的,所以要转换。高德地图里面的dev是否偏移(0:lat和lon是已经加密后的,不需要国测加密;1:需要国测加密),所以如果高德地图导航的终点不准的话,可以换下这个值。

你可能感兴趣的:(iOS一次跳转到第三方地图导航小记)