5 years ago (2016-02-17)  Algorithm language Software development |   First to comment  1374 
post score 0 times, average 0.0

When starting to use the Baidu Maps API for development, you may encounter quite a strange thing. Using Baidu's latitude and longitude to locate on the map is quite inaccurate. This problem was encountered during the development of WeChat and Android.The first time using the Baidu map api to get the location and display it on the map is when the WeChat development, it is not knowing the specific reason but can't get an offset in the WeChat acquisition location to calibrate, although it can barely solve, but Not quite accurate.Later on at the beginning of Android also encountered this problem, only to find Baidu map API positioning offset is not an accidental problem.

Baidu map API positioning offset reason

The following is from the internet:

First, the coordinate system

First of all, we have to understand what coordinate systems developers can access?

The first classification:

1, GPS, WGS-84, the original coordinate system.The coordinates recorded by an international standard GPS recorder are all GPS coordinates.Unfortunately, in China, GPS coordinates are not allowed on any of the map products. It is said to be confidential.The GPS coordinates are shown in the form of latitude and longitude in latitude and longitude: Baidu map API offset calibration algorithm 1 Baidu map API position offset calibration algorithm 2 2, GCJ-02, the Coordinate System released by the State Bureau of Survey in 2002.Also known as "Mars".In China, you must use at least the GCJ-02 coordinate system.For example, Google, Tencent and Gao De are all using this coordinate system.GCJ-02 is also the most widely used coordinate system in China. 3, other coordinate system.It is generally obtained by the GCJ-02 offset algorithm.This system is based on the difference of each company, the coordinate system is not the same.For example, Baidu and Sogou use their own coordinate system and are incompatible with other coordinate systems.

The second category:

First understand that the origin of all coordinate systems is Africa. Baidu map API position offset calibration algorithm 1, latitude and longitude.This is a spherical coordinate. For Beijing, this is the coordinate (116.38817139.935961).Such as Tencent, Gold, Baidu are such latitude and longitude coordinates.Google is latitude and longitude in the order of latitude and longitude coordinates. If it is the minutes, minutes and seconds coordinates, it needs to be converted to get such latitude and longitude coordinates.See coordinate conversion for details. 2, Mercator coordinates.Plane coordinates, which are equivalent to straight-line distances, are generally larger numbers, like this.(215362.00021333335 99526.00034912192) Mercator coordinates, mainly used for the background calculation of the program.Straight line distance, plus or minus the reduction is almost easy to calculate. The Sogou Maps API is a Mercator coordinate that is used directly.

Second, the coordinate conversion

The coordinates taken on various web-side platforms, or on Gold German, Tencent and Baidu, are not GPS coordinates, they are all GCJ-02 coordinates, or their own offset coordinate system. For example, all you have on the Google Maps API, GotMap API, and Tencent Maps API are GCJ-02 coordinates. All three of them are generic, and they also apply to most of the map API products and their map products. Exceptions. The Baidu API is based on BD-09 coordinates and is only applicable to Baidu Maps related products. Exceptions. The Sogou API is based on Sogou coordinates and is only applicable to Sogou Map related products. Exceptions, Google Earth, google earth to get is the GPS coordinates, but also in latitude and longitude latitude and longitude coordinates.Not allowed in the country.Must be converted to GCJ-02 coordinates.

1 degrees, minutes, seconds, coordinates to latitude and longitude

For example, if a GPS logger or google earth captures 39°31'20.51, then it should be converted like this, 31 points is 31/60 degrees, and 20.51 seconds is 20.51/3600 degrees. The result is 39 + 31/60 + 20.51/3600 degrees.

2, GPS converted to GCJ-02 coordinates

Google, Gaode, and Tencent's Map API official website do not directly provide such coordinate conversion.If you want to get GCJ-02 coordinates, it is best to take points directly on their maps, or through address resolution.(This tool will be posted later.)I love doing this kind of thing, haha.) However, such an interface was found on the Internet. The type=1 of this interface is the Mercator coordinate of the GPS to GCJ-02.Please keep the interface secret, haha.See: http://map.sogou.com/api/documentation/javascript/api2.5/interface_translate.html#late_intro

3、Transition between GCJ-02 and BD-09

The transformation of the National Bureau of Surveying System's GCJ-02 coordinate system (Google, Gold German, Tencent) and Baidu's BD-09 system is explained in detail on CSDN: http://blog.csdn.net/coolypf/article/ Details/8569813 But there are also simpler algorithms, linear algorithms (lat and lng are latitude and longitude, spherical coordinates): To_B is to Baidu, To_G is to GCJ-02. Var TO_BLNG = function(lng){return lng+0.0065;}; var TO_BLAT = function(lat){return lat+0.0060;}; var TO_GLNG = function(lng){return lng-0.0065;}; var TO_GLAT = function( Lat){return lat-0.0060;};

4, latitude and longitude into Mercator

There is also a detailed explanation on the Internet: http://bbs.esrichina-bj.cn/esri/viewthread.php?tid=78245 (We did not find that Gao De is an api, Tencent and Baidu are mapapi, what does it mean?Third, the coordinate offset If your coordinates after the conversion, there is an offset, then consider the following aspects. A. The original coordinate system is mistaken, for example, if you think you are GPS coordinates, but it is actually GCJ-02 coordinates. Solution: Make sure which coordinate system is used for the acquired data, which coordinate system you need to convert to, and then perform the coordinate transformation. B. The original coordinates are not accurate. Solution: If you are using GPS coordinates, make sure to collect at least 4 satellites when collecting GPS data.And GPS data is not accurate, but also depends on the height of the surrounding buildings, the higher the more inaccurate, because there is shelter. If it were originally GCJ-02 coordinates, it may not be the same in different map zoom levels.For example, when you zoom in to map level 12 (street) at the map level 4 (country), the coordinates are off.Make sure to pick up the coordinates at the map's maximum magnification level. C, the concept of the degree of minutes and seconds confusion For example, in google earth collected is 39 ° 31'20.51, then it should be converted, 31 points is 31/60 degrees, 20.51 seconds is 20.51/3600 degrees, the result is 39 + 31 /60 + 20.51/3600 degrees. D. Latitude and longitude are reversed. Some companies (such as Gold, Baidu and Tencent) are first longitude and then latitude, ie Point (lng lat).However, the order of Google coordinates is exactly the opposite, which is (lat lng). Related issues Baidu explained: http://developer.baidu.com/map/question.htm

Baidu map API position offset calibration algorithm

C++ algorithm



This article has been printed on copyright and is protected by copyright laws. It must not be reproduced without permission.If you need to reprint, please contact the author or visit the copyright to obtain the authorization. If you feel that this article is useful to you, you can click the "Sponsoring Author" below to call the author!

Reprinted Note Source: Baiyuan's Blog>>https://wangbaiyuan.cn/en/baidu-map-api-position-offset-calibration-algorithm-2.html

Post comment


No Comment


Forget password?