Goals and Boundaries
- Goals: Correctly integrate the Baidu Location SDK in an Android project, and provide a location implementation solution that complies with privacy, AK, and coordinate system specifications.
- Responsible for: Single/continuous location, LocationClientOption parameter configuration, geofencing (circular/polygonal), reverse geocoding, BDLocation field parsing; subject to the references within the skill.
- Not responsible for: Baidu Map SDK map display (see the baidu-map-android-sdk skill), server-side logic, UI visual design.
When to Use
Enable this skill if any one of the following is met:
- Keywords: Baidu Location, LocationClient, BDLocation, LocationClientOption, geofencing, GeoFence, reverse geocoding, BD09LL, coordinate system
- Requirement types: obtaining the current location, continuous location, trajectory recording, entry/exit area monitoring, coordinate-to-address conversion, indoor positioning
Load on demand: First select a document from reference.md according to the requirement, then reference the corresponding references content; if the requirement is ambiguous, first clarify with the userbefore giving a solution。
Rules That Must Be Followed
-
Privacy compliance (v9.x+)
- Before calling any SDK interface, user consent must first be obtained and the privacy interface must be called:
LocationClient.setAgreePrivacy(true), andmust be beforenew LocationClient(context)calledSee the overview.md privacy compliance subsection.
- Before calling any SDK interface, user consent must first be obtained and the privacy interface must be called:
-
AK and configuration
- Before use, apply for an Android SDK key (AK) in the console, select "Android SDK" as the application type, and fill in the package name and SHA1. Configure the AK in AndroidManifest's
<meta-data>; the package name and signature must match those at the time of application. See overview.md。
- Before use, apply for an Android SDK key (AK) in the console, select "Android SDK" as the application type, and fill in the package name and SHA1. Configure the AK in AndroidManifest's
-
Lifecycle management
- In the Activity/Service's
onDestroy, you must callmLocationClient.stop(), to avoid the location service continuing to run and consuming battery.
- In the Activity/Service's
-
Unified coordinate system
- By default, it is recommended to use
bd09ll; if used together with the Baidu Map SDK, the coordinate system must be kept consistent. For coordinate system descriptions, see location-config.md。
- By default, it is recommended to use
-
Listener before start
- You must first call
registerLocationListenerto register the listener, then callstart()to start location; otherwise callbacks may not be received.
- You must first call
-
Versions and APIs are subject to the project
- If the user has already integrated the SDK, the version within their project prevails. If a certain class or method does not exist,prompt the user to update the dependency to a compatible versionand then retry; do not forcibly write non-existent APIs.
Output specifications (evaluable)
- Actionable: Includes specific class names, methods, call order, and necessary configuration (AndroidManifest, AK, privacy, location Service).
- Verifiable: Privacy and AK are explicit; the listener-before-start order is correct; if location failure is involved, the solution can point to the troubleshooting items of errorcode.md or project-config.md .
- Composable: By reference.md select documents and common combinations.
Solution structure: requirement → corresponding document → configuration and dependencies → key API → example snippet → notes.
Reference index
- Select documents and common combinations by requirement:reference.md
- Gradle dependencies (basic package/full package/version notes):gradle.md
- AndroidManifest, permissions, location Service, obfuscation:project-config.md
- Integration steps, AK, privacy compliance, LocationClient initialization:overview.md
- Single/continuous location, BDLocation fields, location type:basic-location.md
- LocationClientOption all parameters, scenario-based configuration:location-config.md
- Circular/polygon geofencing, entry and exit event listening:geofence.md
- Reverse geocoding, address fields, POI nearby search:geocode.md
- Location result error codes (locType) and authentication error codes:errorcode.md
- Class and package quick reference:class-reference.md