Baidu map positioning position deviation problem in android development

Recently, when I was doing Android development, I used Baidu Maps API. After doing a demo according to the official documentation, I found that the location displayed on the map deviated greatly from the actual location. I queried the coordinates on Google Maps and found the location displayed by the coordinates. It is accurate, but there is a deviation on the Baidu Map API.

Domestic mainstream coordinate system types

There are mainly three types:

1. WGS84: It is a geodetic coordinate system and is also the coordinate system used by the currently widely used GPS global satellite positioning system;

2. GCJ02: It is the coordinate system of the geographical information system formulated by the China National Bureau of Surveying and Mapping. It is an encrypted coordinate system based on the WGS84 coordinate system;

3. BD09: Baidu coordinate system, encrypted again based on the GCJ02 coordinate system. Among them, BD09ll represents Baidu latitude and longitude coordinates, and BD09mc represents Baidu Mercator coordinates.

Baidu's official introduction to coordinates: https://lbsyun.baidu.com/index.php?title=androidsdk/guide/coordtrans

Therefore, you need to set the coordinate system when initializing the position, code:

Recently, when I was doing Android development, I used Baidu Maps API. After doing a demo according to the official documentation, I found that the location displayed on the map deviated greatly from the actual location. I queried the coordinates on Google Maps and found the location displayed by the coordinates. It is accurate, but there is a deviation on the Baidu Map API.

Domestic mainstream coordinate system types

There are mainly three types:

WGS84: It is a geodetic coordinate system and is also the coordinate system used by the widely used GPS global satellite positioning system.

GCJ02: It is the coordinate system of the geographical information system formulated by the China National Bureau of Surveying and Mapping. It is an encrypted coordinate system from the WGS84 coordinate system.

BD09: Baidu coordinate system, encrypted again based on the GCJ02 coordinate system. Among them, BD09ll represents Baidu latitude and longitude coordinates, and BD09mc represents Baidu Mercator coordinates.

Baidu’s official introduction to coordinates:

https://lbsyun.baidu.com/index.php?title=androidsdk/guide/coordtrans

Therefore, you need to set the coordinate system when initializing the position. The code is as follows:

private void initLocation() {

LocationClientOption option =new LocationClientOption();

    //Set the time interval for initiating positioning requests, which is valid if it is greater than 1000ms

    option.setScanSpan(5000);

    //Set the coordinate system. If not set, the default is GCJ02 coordinate system.

    option.setCoorType("bd09ll");

    ​ option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy);//Set the location mode

    option.setIsNeedAddress(true);//Set whether geographical location is required

    mLocationClient.setLocOption(option);

}

Mainly this sentence

option.setCoorType("bd09ll");


 

Guess you like

Origin blog.csdn.net/qq_33209777/article/details/134304490