Conversion between Baidu map coordinates and Gaode map coordinates


There are many posts on the Internet to solve this type of problem, but here you need to record your own problem-solving process.

Demand background :

The Baidu coordinate system BD-09 is used in the project. When the APP jumps to the Gaode map APP, although the coordinates have been converted, there is still an offset displayed on the Gaode map. Hence the question: solve the coordinate offset problem.

Solution ideas :

Start from the following aspects:
1. The original coordinate system is wrong, for example, you think you are GPS coordinates, but in fact it is GCJ-02 coordinates.
Solution: Please make sure which coordinate system the collected data is in, which coordinate system needs to be converted to, and then perform coordinate conversion.
2. The accuracy of the original coordinates is not enough
Solution: If you are GPS coordinates, please ensure that at least 4 satellites are found when collecting GPS data. And whether the GPS data is accurate or not depends on the height of the surrounding buildings. The higher the height, the more inaccurate it will be because of occlusion.
If it is the coordinates of GCJ-02, the places you see may be different at different map zoom levels. For example, when you zoom in to level 12 (street) of the coordinates you obtained at map level 4 (country), the coordinates will be off. Make sure to pick up the coordinates when the map is at its maximum zoom level.
3. The concepts of degrees, minutes, and seconds are confused.
For example, the data collected on Google Earth is 39°31'20.51, so it should be converted in this way. 31 minutes is 31/60 degrees, and 20.51 seconds is 20.51/3600 degrees. The result is 39 + 31 /60 + 20.51/3600 degrees.
4. The order of latitude and longitude is reversed.
Some companies (such as AutoNavi, Baidu, and Tencent) write longitude first, then latitude, that is, Point(lng lat). But the order of Google coordinates is just the opposite, it is (lat lng).

Program implementation :

1. Print the log in the program to get the Baidu coordinate system, pass the converted Mars coordinate system, and verify whether the converted result is correct. The verification tool: Baidu coordinate picker ( http://api.map.baidu.com/ lbsapi/getpoint/index.html ), Gaode coordinate picker ( http://lbs.amap.com/console/show/picker ).
Here it is found that there is a problem with the conversion algorithm, and the conversion result is biased. The algorithm should be adopted: http://blog.csdn.net/w605283073/article/details/64906518

2. After converting from the Baidu coordinate system to get the correct Mars coordinate system, jumping from your own APP to Gaode map and found that there is still an offset. Then the problem must be in the process of APP jumping. Therefore, it is found that there is a problem with the jump code, and the correct jump code is posted directly below:

// viewMap-服务类型,
// sourceApplication-第三方调用应用名称,
// poiname-POI名称,
// lat-经纬度参数,lon-经纬度参数,
// dev-起终点是否偏移(0:lat和lon是已经加密后的,不需要国测加密;1:需要国测加密)
Intent intent = new Intent("android.intent.action.VIEW",                  android.net.Uri.parse("androidamap://navi?sourceApplication=我的应用&poiname=应用&lat="
+ loc.getLat() + "&lon=" + loc.getLng()
+ + "&dev=0"));
intent.setPackage("com.autonavi.minimap");
context.startActivity(intent);

Note: For the dev parameter here, it is generally necessary to write dev=0, that is, through the conversion algorithm in step 1, the coordinates are already encrypted by the national survey, and there is no need to perform national survey encryption, otherwise the obtained results will be displayed on the map. offset. Referenced here ( http://blog.csdn.net/u010998327/article/details/71515147 )

In summary, after the above steps, the coordinate conversion offset problem is fixed. By analogy, the solution to the conversion and offset problems of other coordinate systems should be as above, such as: the conversion of the Mars coordinate system to the Baidu coordinate system, the mutual conversion between the WGS-84 coordinate system and Baidu, etc.

References :

https://segmentfault.com/a/1190000000498434
http://blog.csdn.net/u010998327/article/details/71515147
http://blog.csdn.net/w605283073/article/details/64906518

Guess you like

Origin blog.csdn.net/lrxb_123/article/details/78804869