Requirements: Convert Baidu coordinates to WGS84 coordinates Implementation: First of all, let me introduce many complicated coordinate systems in China, as we all know, the United States GPS uses WGS84 coordinates, but in China, for security reasons, when the map is released and published, the 84 coordinates are non-linear and biased, and the coordinates obtained are called GCJ02 coordinate systems, commonly known as Mars coordinates. In addition, many domestic map companies, perhaps due to business needs or some reasons for business competition, have carried out a nonlinear deviation on the basis of Mars coordinates and obtained their own coordinate system. Baidu is such a company. Baidu carried out BD-09 secondary nonlinear bias on the basis of GCJ02 and obtained its own Baidu coordinate system. This may be beneficial to Baidu's own company, but for us developers, it is simply annoying. The following is a brief introduction to the coordinate systems used by some map service providers in China:
Currently, Baidu provides an API for coordinate conversion, http://api.map.baidu.com/ag/coord/convert?from=0&to=4&x=longitude&y=latitude thereinto • from: Source coordinate system (0 for original GPS coordinates, 2 for Google coordinates) • to: Converted coordinates (4 is Baidu's own, as if this must be 4) • x: Precision • y: Latitude The result returned is a json string: {"error":0,"x":"MTIxLjUwMDIyODIxNDk2","y":"MzEuMjM1ODUwMjYwMTE3"} • error: is the error mark bit, and "0" indicates OK • x: Accuracy of Baidu coordinate system (Base64 encryption) y: Latitude of Baidu coordinate system (Base64 encryption); I collected the meaning of these two numbers online:
http://api.map.baidu.com/ag/coord/convert?from=0&to=4&x=longitude&y=latitude 1: Angular coordinates obtained by GPS equipment; 2: Metric coordinates obtained by GPS, coordinates used in sogou maps; 3: Coordinates used for Google Maps, SOSO Maps, Aliyun Maps, MapABC Maps, and AMAP Maps 4:3 The meter coordinates corresponding to the coordinates of the map in the list 5: The longitude and latitude coordinates used by Baidu Maps 6: Metric coordinates used by Baidu Maps 7: mapbar map coordinates; 8:51 Map coordinates No default is 1, which is the coordinates obtained by the GPS device To destination coordinate types there are two options: 5, 6. 5: BD09LL (Baidu latitude and longitude coordinates), 6: BD09MC (latitude and longitude coordinates in 100 degrees meters); No The default is 5, i.e. bd09ll (Baidu coordinates)
The above are all used to convert 84 coordinates to Baidu coordinates, below, let's talk about how to achieve the reverse conversion of coordinates, that is, Baidu coordinates are converted to 84 coordinates. I found a lot of algorithms on the Internet, and most of them are limited to one offset, that is, the interchange between Baidu coordinates and Mars coordinates, the interchange between Mars coordinates and Earth coordinates, etc., and there is little mention of Baidu coordinates to 84 coordinates. In this regard, I tried to convert Baidu coordinates to Mars coordinates first, and then convert the Martian coordinates to Earth coordinates, but the result was not satisfactory, the lowest error was 60 meters, and the most was even more than 600 meters of error, so I had to give up. I won't post the algorithm anymore, interested students can go to the Internet to find it by themselves. Here, I use a clever method, the specific method is as follows: Baidu coordinates and GPS coordinate conversion are very close at close distances. Suppose you have Baidu coordinates: x1=116.397428, y1=39.90923 Take this coordinate as a GPS coordinate and get his Baidu coordinates through the interface: x2=116.41004950566, y2=39.916979519873
The coordinates of the GPS can be obtained by calculation: x = 2*x1-x2,y = 2*y1-y2 x=116.38480649434001 y=39.901480480127。 In order to verify the accuracy of this method, I took the coordinates of 14 major cities in China, southeast, northwest, and northwest of China for testing, and the results obtained the results with a deviation of 13 meters and a minimum of 0.x meters. The comprehensive error is 6 meters. The specific test results will be posted later. Let me draw a simple diagram to illustrate this issue.
G represents the original unconverted Earth coordinates; B represents the Baidu coordinates after G is converted through Baidu api; G' represents the coordinates after point B is converted through Baidu API; Assuming that the offset value after converting Google coordinates to Baidu coordinates is small, then the G-point coordinates are perfectly equal to 2B-G’。 After verification, the offset value after converting Google coordinates to Baidu coordinates is about a few hundred meters, which is actually negligible, so use this method to solve the problem of offset library with Baidu's own API, and then ignore the impact of converting offset values. Of course, this method also has a big disadvantage, that is, it requires that these two points must be in the same offset database, if it happens to be located in two different offset libraries, the error may be relatively large. In addition, there is another method that is currently being prepared for further research, which is to establish an offset library and use this offset library to further eliminate this impact: it is still to be studied. Here is the disadvantage of online conversion: Baidu online API conversion tool actually has a limit on the amount of data converted, each key can only convert about 5,000 pieces of data, and an account can apply for up to 20 keys, so if the amount of data is large, it is actually not recommended to use this kind of online conversion, which is also the original intention of studying the local offset library. In addition, because the web side may be more restricted, network speed, concurrent requests, etc. may affect the results and affect the user experience, so the above methods are only for reference.
|