All Products
Search
Document Center

Access Android

Last Updated: May 25, 2021

The location-based services (LBS) SDK is a set of simple LBS interfaces. You can use this set of LBS API to obtain positioning results.

The LBS component can connect to the mPaaS in the native AAR mode, the mPaaS Inside mode, and the component mode.

Before you begin

  • If you want to connect the component to the mPaaS based on the native AAR mode, you need to first complete the prerequisites and the subsequent steps. For more information, see Add mPaaS to your project
  • If you want to connect the component to the mPaaS based on the mPaaS Inside mode, you need to first complete the mPaaS Inside access procedure.
  • If you want to connect the component to the mPaaS based on components, you need to first complete the Component-based access procedure.

Add the SDK

Native AAR mode

In your project, install the LBS component on the Component Management (AAR) page. For more information, see Manage component dependencies in the native AAR mode.

mPaaS Inside mode

In your project, install the LBS component on the Component Management page.
For more information, see Manage component dependencies.

Component-based mode

In your Portal and Bundle projects, install the LBS component on the Component Management page.
For more information, see Manage component dependencies.

Apply for an AMAP key

Before you use the LBS, go to the AMAP Open Platform to apply for an account and obtain the LBS key. The following figure shows an example of a key.

2

Configure the AndroidManifest.xml file

Add the AMAP positioning key and AMAP positioning service to the AndroidManifest.xml file.

 
  1. <!--The AMAP positioning key-->
  2. <meta-data
  3. android:name="com.amap.api.v2.apikey"
  4. android:value="The AMAP positioning key that you applied for" />
  5. <!--The AMAP positioning service-->
  6. <service android:name="com.amap.api.location.APSService"></service>

For the baseline version 10.1.68.18 and later, the auto check-in feature is disabled by default. To enable this feature, add the following code to the AndroidManifest.xml file:

 
  1. <meta-data android:name="com.mpaas.lbs.autoCheckIn" android:value="true" />

API description

  • Call the positioning service
       
    1. LBSLocationManagerProxy.getInstance().requestLocationUpdates(MainActivity.this, new LBSLocationListener() {
    2. @Override
    3. public void onLocationUpdate(LBSLocation lbsLocation) {
    4. Toast.makeText(MainActivity.this, "lbsLocation is " + lbsLocation.getAddress(), Toast.LENGTH_LONG).show();
    5. }
    6. @Override
    7. public void onLocationFailed(int i) {
    8. Toast.makeText(MainActivity.this,
    9. "onLocationFailed" + i, Toast.LENGTH_SHORT).show();
    10. }
    11. });
  • Call other API operations
       
    1. // Register the location listener.
    2. public void requestLocationUpdates(Context context, LBSLocationListener locationListener)
    3. // Remove the callback of the location monitoring registration.
    4. public void removeUpdates(Context context, LBSLocationListener listener)
    5. // Obtain the location of the latest successful positioning.
    6. public LBSLocation getLastKnownLocation(Context context)