Jump to Baidu and Gaode third-party map navigation in the app

In the project, I encountered the need to jump to third-party navigation based on latitude and longitude. I searched on the Internet and found that they were all the same articles, and the destination address could not be displayed correctly. After no results, I went to the official websites of Baidu and Gaode Maps to search. The location is very hidden. , share with you

1. Call the Gaode Map APP

There are two ways to call the Gaode Map APP:

  • One is to achieve by accessing the URI address of the web. The effect of writing this way is that the APP will jump to the browser to access the Gaode map on the H5 page. If the parameter is set to 1, the browser will ask you whether you need to callnativeopen the Gaode map app

    https://uri.amap.com/navigation?from=116.478346,39.997361,startpoint&to=116.3246,39.966577,endpoint&via=116.402796,39.936915,midwaypoint&mode=car&policy=1&src=mypage&coordinate=gaode&callnative=0
    

    Jump to official documents by WEB-URI

  • The other is the commonly used direct jump method, which is URL_TYPErealized directly through the Gaode APP. This method needs to be based on the latitude and longitude database of the starting point and the latitude and longitude of the destination, and the address of the destination can be set. If the destination address is Empty, the map will display the points that are not on the map

    //访问地址示例(直接发起导航)
    iosamap://navi?sourceApplication=applicationName&poiname=fangheng&poiid=BGVIS&lat=36.547901&lon=104.258354&dev=1&style=2
    
    //访问地址示例(路线规划)
    iosamap://path?sourceApplication=applicationName&sid=&slat=39.92848272&slon=116.39560823&sname=A&did=&dlat=39.98848272&dlon=116.47560823&dname=B&dev=0&t=0
    
    

    Directly jump to the official document of Gaode APP

2. The APP invokes the Baidu Map APP

Baidu Maps URL_TYPEdirectly jumps to Baidu Maps APP through the method, and the destination address can be set in the link. When Baidu Maps sets the destination address, the document says that it is relatively vague. It needs to be set in the following format: destination=name:destination address|latlng:40.007623, 116.360582, separated by vertical lines

//访问地址示例(路线规划)
baidumap://map/direction?origin={
    
    {
    
    我的位置}}&destination=name:目的地地址|latlng:40.007623,116.360582&coord_type=bd09ll&mode=driving&src=ios.baidu.openAPIdemo

Jump directly to Baidu APP official document

3. Mutual conversion of Baidu and Gaode coordinates


/** 百度地图转高德地图坐标 */
- (CLLocationCoordinate2D) bd_decrypt:(double)bd_lat bd_lon:(double)bd_lon
{
    
    
  double x = bd_lon - 0.0065, y = bd_lat - 0.006;
  double z = sqrt(x * x + y * y) - 0.00002 * sin(y * x_pi);
  double theta = atan2(y, x) - 0.000003 * cos(x * x_pi);
  CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(z * sin(theta), z * cos(theta));
  return coordinate;
}


/** 高德地图转百度地图坐标 */
- (CLLocationCoordinate2D) bd_decrypt:(double)gg_lat gg_lon:(double)gg_lon
{
    
    
  double x = gg_lon, y = gg_lat;
  double z = sqrt(x * x + y * y) + 0.00002 * sin(y * x_pi);
  double theta = atan2(y, x) + 0.000003 * cos(x * x_pi);
  
  CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(z * sin(theta)+0.006, z * cos(theta)+0.0065);
  return coordinate;
}

Guess you like

Origin blog.csdn.net/zhanglei5415/article/details/131461330