All service products
Developer Channel
Service upgrade
Sign in
Android Positioning SDK
Baidu Maps Android Positioning SDK is a set of simple and easy-to-use positioning service interfaces for Android mobile applications, focusing on providing the best comprehensive positioning services for developers. By using Baidu Positioning SDK, developers can easily realize intelligent, accurate and efficient positioning functions for applications.
This service currently supports the acquisition of overseas longitude and latitude information.

Important: In order to further strengthen the security protection measures for the end user's personal information, developers must ensure that the privacy compliance interface setAgreePrivacy is called before calling any interface of the SDK from the positioning SDK v9.2.9 version, or the related functions may not be used normally. For details, please refer to Privacy Compliance Interface explain.

Free Instructions
Currently, developers of Baidu Maps Android Positioning SDK domestic services for non-commercial purposes No charge , developers can download Use with confidence. If you use the services of the platform for commercial purposes (including but not limited to charging third-party users, project bidding, and other direct or indirect gains or benefits), users must obtain the platform in advance“ Commercial authorization "License. The authorized object of the platform's commercial authorization is the company's main body. After the authorization is successful, you will receive the written commercial authorization provided by the platform (with the signature and seal of Baidu). The commercial authorization can click here Learn more.
Function introduction
Basic positioning
brief introduction
The core capability of the positioning SDK is to help developers quickly and accurately obtain user positioning. The developer only needs to follow the following process to obtain the user's current longitude and latitude.
Function display
/**
*Initialize positioning parameter configuration
*/
private void initLocationOption ( ) {
//Locate the client of the service. The host program declares this class on the client and calls it. Currently, it only supports starting in the main thread
LocationClient locationClient = new LocationClient ( getApplicationContext ( ) ) ;
//Declare LocationClient class instance and configure location parameters
LocationClientOption locationOption = new LocationClientOption ( ) ;
MyLocationListener myLocationListener = new MyLocationListener ( ) ;
//Register listener function
locationClient . registerLocationListener ( myLocationListener ) ;
//Optional, default high-precision, set positioning mode, high-precision, low-power, device only
locationOption . setLocationMode ( LocationMode . Hight_Accuracy ) ;
//Optional, default gcj02, set the returned positioning result coordinate system. If it is used with Baidu Maps, it is recommended to set it to bd09ll;
locationOption . setCoorType ( "gcj02" ) ;
//Optional, the default is 0, that is, the location is only made once. It is valid to set the interval between successive location requests to be greater than or equal to 1000ms
locationOption . setScanSpan ( one thousand ) ;
//Optional. Set whether address information is required. It is not required by default
locationOption . setIsNeedAddress ( true ) ;
//Optional, set whether address description is required
locationOption . setIsNeedLocationDescribe ( true ) ;
//Optional, set whether the equipment direction result is required
locationOption . setNeedDeviceDirect ( false ) ;
//Optional, default false, set whether to output satellite positioning results at 1S1 frequency when satellite positioning is valid
locationOption . setLocationNotify ( true ) ;
//Optional. The default is true. Locate the SDK as a SERVICE and place it in an independent process. Set whether to kill the process at the time of stop. The default is not to kill the process
locationOption . setIgnoreKillProcess ( true ) ;
//Optional, false by default, set whether to need location semantic results, which can be obtained in BDLocation.getLocationDescription, and the results are similar to "near Tiananmen Square in Beijing"
locationOption . setIsNeedLocationDescribe ( true ) ;
//Optional, false by default, set whether POI results are required, which can be obtained in BDLocation.getPoiList
locationOption . setIsNeedLocationPoiList ( true ) ;
//Optional, default false, set whether to collect CRASH information, default collection
locationOption . SetIgnoreCacheException ( false ) ;
//Optional, default false, set whether to enable satellite positioning
locationOption . setOpenGnss ( true ) ;
//Optional. The default is false. It is used to set whether altitude information is required during positioning. It is not required by default. Except for the basic positioning version, it is available
locationOption . setIsNeedAltitude ( false ) ;
//Set to turn on the automatic location callback mode. When this switch is turned on, as long as the location SDK detects a location change, it will actively call back to the developer. In this mode, the developer no longer needs to care about the location interval, but the location SDK itself will timely call back to the developer when it finds a location change
locationOption . setOpenAutoNotifyMode ( ) ;
//Set to turn on the automatic callback position mode. When this switch is turned on, as long as the positioning SDK detects a position change, it will actively call back to the developer
locationOption . setOpenAutoNotifyMode ( three thousand , one , LocationClientOption . LOC_SENSITIVITY_HIGHT ) ;
//The configured LocationClientOption object needs to be passed to the LocationClient object through the setLocOption method for use
locationClient . setLocOption ( locationOption ) ;
//Start positioning
locationClient . start ( ) ;
}
/**
*Realize positioning callback
*/
public class MyLocationListener extends BDAbstractLocationListener {
@ Override
public void onReceiveLocation ( BDLocation location ) {
//BDLocation here is the location result information class. All the results related to location can be obtained through its various get methods
//The following is only a partial list of results related to longitude and latitude (commonly used)
//For more result information, please refer to the description in BDLocation class in the class reference
//Get latitude information
double latitude = location . getLatitude ( ) ;
//Get longitude information
double longitude = location . getLongitude ( ) ;
//Get the positioning precision, the default value is 0.0f
float radius = location . getRadius ( ) ;
//Obtain the longitude and latitude coordinate type, which is subject to the coordinate type set in LocationClientOption
String coorType = location . getCoorType ( ) ;
//Get the location type and location error return code. For specific information, refer to the description in BDLocation class in the class reference
int errorCode = location . getLocType ( ) ;
}
}
Continuous positioning
brief introduction
In the actual positioning scene, there may be a lot of position jitter. This example shows a smooth optimization processing of the positioning results. In the actual test, this smoothing strategy has obvious smoothing effect in the urban pedestrian scene, effectively reducing some jitters, and opening the algorithm logic (the specific algorithm is found in the LocationFilter class of the official website demo), hoping to help developers.
Function display
/**
*Initialize positioning parameter configuration
*/
private void initLocationOption ( ) {
//Locate the client of the service. The host program declares this class on the client and calls it. Currently, it only supports starting in the main thread
LocationClient locationClient = new LocationClient ( getApplicationContext ( ) ) ;
//Declare LocationClient class instance and configure location parameters
LocationClientOption locationOption = new LocationClientOption ( ) ;
MyLocationListener myLocationListener = new MyLocationListener ( ) ;
//Register listener function
locationClient . registerLocationListener ( myLocationListener ) ;
//Optional, default high-precision, set positioning mode, high-precision, low-power, device only
locationOption . setLocationMode ( LocationMode . Hight_Accuracy ) ;
//Optional, default gcj02, set the returned positioning result coordinate system. If it is used with Baidu Maps, it is recommended to set it to bd09ll;
locationOption . setCoorType ( "gcj02" ) ;
//Optional, the default is 0, that is, the location is only made once. It is valid to set the interval between successive location requests to be greater than or equal to 1000ms
locationOption . setScanSpan ( one thousand ) ;
//Optional. Set whether address information is required. It is not required by default
locationOption . setIsNeedAddress ( true ) ;
//Optional, set whether address description is required
locationOption . setIsNeedLocationDescribe ( true ) ;
//Optional, set whether the equipment direction result is required
locationOption . setNeedDeviceDirect ( false ) ;
//Optional, default false, set whether to output Gnss results at 1S1 frequency when Gnss is valid
locationOption . setLocationNotify ( true ) ;
//Optional. The default is true. Locate the SDK as a SERVICE and place it in an independent process. Set whether to kill the process at the time of stop. The default is not to kill the process
locationOption . setIgnoreKillProcess ( true ) ;
//Optional, false by default, set whether to need location semantic results, which can be obtained in BDLocation.getLocationDescription, and the results are similar to "near Tiananmen Square in Beijing"
locationOption . setIsNeedLocationDescribe ( true ) ;
//Optional, false by default, set whether POI results are required, which can be obtained in BDLocation.getPoiList
locationOption . setIsNeedLocationPoiList ( true ) ;
//Optional, default false, set whether to collect CRASH information, default collection
locationOption . SetIgnoreCacheException ( false ) ;
//Optional, default false, set whether to enable satellite positioning
locationOption . setOpenGnss ( true ) ;
//Optional. The default is false. It is used to set whether altitude information is required during positioning. It is not required by default. Except for the basic positioning version, it is available
locationOption . setIsNeedAltitude ( false ) ;
//Set to turn on the automatic location callback mode. When this switch is turned on, as long as the location SDK detects a location change, it will actively call back to the developer. In this mode, the developer no longer needs to care about the location interval, but the location SDK itself will timely call back to the developer when it finds a location change
locationOption . setOpenAutoNotifyMode ( ) ;
//Set to turn on the automatic callback position mode. When this switch is turned on, as long as the positioning SDK detects a position change, it will actively call back to the developer
locationOption . setOpenAutoNotifyMode ( three thousand , one , LocationClientOption . LOC_SENSITIVITY_HIGHT ) ;
//The configured LocationClientOption object needs to be passed to the LocationClient object through the setLocOption method for use
locationClient . setLocOption ( locationOption ) ;
//Start positioning
locationClient . start ( ) ;
}
/**
*Realize positioning callback
*/
public class MyLocationListener extends BDAbstractLocationListener {
@ Override
public void onReceiveLocation ( BDLocation location ) {
//BDLocation here is the location result information class. All the results related to location can be obtained through its various get methods
//The following is only a partial list of results related to longitude and latitude (commonly used)
//For more result information, please refer to the description in BDLocation class in the class reference
//Get latitude information
double latitude = location . getLatitude ( ) ;
//Get longitude information
double longitude = location . getLongitude ( ) ;
//Get the positioning precision, the default value is 0.0f
float radius = location . getRadius ( ) ;
//Obtain the longitude and latitude coordinate type, which is subject to the coordinate type set in LocationClientOption
String coorType = location . getCoorType ( ) ;
//Get the location type and location error return code. For specific information, refer to the description in BDLocation class in the class reference
int errorCode = location . getLocType ( ) ;
}
}
Background positioning
brief introduction
In order to maximize the survival rate of the positioning process, Baidu Android Positioning SDK provides the ability to continuously locate in the background, which can continuously record the location information when the application is retired from the background. For details, please refer to the instructions in Android 8.0.
Function display
//The core implementation code is as follows. For details, please refer to the official website Demo.
//Start the foreground positioning service:
Notification . Builder builder = new Notification . Builder ( MainActivity . this . getApplicationContext ( ) ) ;
//Get a Notification constructor
Intent nfIntent = new Intent ( MainActivity . this . getApplicationContext ( ) , MainActivity . class ) ;
builder . setContentIntent ( PendingIntent . getActivity ( MainActivity . this , zero , nfIntent , zero ) ) //Set PendingIntent
. setContentTitle ( Background positioning in progress ) //Set the title in the drop-down list
. setSmallIcon ( R . mipmap . ic_launcher ) //Set small icons in the status bar
. setContentText ( "Background location notification" ) //Set context content
. setAutoCancel ( true )
. setWhen ( System . currentTimeMillis ( ) ) ; //Set the time when this notification occurs
Notification notification = null ;
notification = builder . build ( ) ;
notification . defaults = Notification . DEFAULT_SOUND ; //Set as default sound
mLocClient . enableLocInForeground ( one thousand and one , notification ) ; //Turn up the foreground positioning
//Stop the foreground location service:
mLocClient . disableLocInForeground ( true ) ; //Close foreground positioning and remove the notice bar at the same time
Location Reminder
brief introduction
The location SDK supports the location reminder function. When the user reaches the location area set by the developer, the corresponding prompt will be triggered.
Function display
public LocationClient mLocationClient = null ;
public BDNotifyListener myListener = new MyNotifyListener ( ) ;
/**
*Please declare the LocationClient class object in the main thread. The initialization of this object needs to pass in the Context type parameter. It is recommended to use the getApplicationConext () method to obtain the valid Context of the whole process.
*/
public void onCreate ( ) {
//Declare LocationClient class
mLocationClient = new LocationClient ( getApplicationContext ( ) ) ;
//Register listener function
mLocationClient . registerNotify ( myListener ) ;
}
/**
*Define the MyNotifyLister class, inherit BDNotifyListener, and implement the callback of location listening.
*/
public class MyNotifyLister extends BDNotifyListener {
public void onNotify ( BDLocation mlocation , float distance ) {
//Reached near the set listening position
}
}
//Call the setNotifyLocation method of BDNotifyListener to set the location message reminder.
//Set position reminder. The four parameters are latitude, precision, radius and coordinate type
myListener . setNotifyLocation ( forty . 0f , one hundred and sixteen . 0f , three thousand , mLocationClient . getLocOption ( ) . getCoorType ( ) ) ;
//When positioning is enabled, the SDK will automatically enable the monitoring of location message alerts
mLocationClient . start ( ) ;
//Call the removeNotifyEvent method of BDNotifyListener to cancel location listening
mLocationClient . removeNotifyEvent ( myListener ) ;
Service advantages
Baidu Maps Android Positioning SDK is a set of simple and easy-to-use positioning service interfaces for Android mobile applications, focusing on providing the best comprehensive positioning services for developers. By using Baidu Positioning SDK, developers can easily realize intelligent, accurate and efficient positioning functions for applications.
-Positioning success rate: The overall positioning success rate is as high as 99.6%.
-High positioning accuracy: The satellite positioning accuracy reaches 10 meters, the Wi Fi positioning accuracy reaches 24 meters, and the base station positioning accuracy reaches 107 meters.
-Low flow: The network traffic generated by a single request is 0.3K, and no traffic will be generated when the location is not requested.
-Fast: The network positioning speed reaches 200ms (under normal network environment), and the IP positioning speed is less than 200ms.
-Wide coverage: Mobile, China Unicom and China Telecom have full network coverage, with base station coverage reaching 99% and Wi Fi coverage reaching 99%.
-Stable service: The stability of location service can reach 99.999%.
-Low power consumption: Memory usage is 15.6M, CPU usage is 2.2%.
-Indoor positioning: Covering various scenes such as railway stations, airports, shopping malls, passenger bus stations, museums, general hospitals, libraries, etc., it provides indoor accurate positioning services with an accuracy of 1-3m by using triangular positioning technology, enhanced Wi Fi fingerprint model technology, geomagnetic technology, Bluetooth technology, etc.
Note: If Baidu does not cover your indoor map data, indoor stores and other information changes, update the positioning information at the first time, or other indoor map indoor positioning related needs, you can click here
-Overseas positioning: Baidu currently covers more than 200 countries and regions around the world, supports 52 languages around the world, and has a total overseas POI of more than 100 million and a road network of 70 million kilometers.
Application scenarios
-Intelligent hardware: Represented by smart wearables, smart homes, intelligent transportation devices and VR devices, it solves the problem of user positioning and helps developers to achieve user precise positioning, remote positioning, geographical fence monitoring and reminding and other functions.
-E-commerce shopping: Recommend goods for users based on their exact location, automatically fill in the receiving address for users, optimize the delivery experience, and view the transportation location in real time through precise positioning.
-Travel service: Provide travel car service for developers, use accurate positioning and location description to define the starting point and end point of car use, and help drivers better find car users.
-Audio visual entertainment: Use precision positioning services to obtain users' locations, recommend LBS based content for users, recommend other users around, enhance users' social attributes, and assist developers in precision marketing push for users.

Next

Get Key

Is this article helpful to you?