All Products
Search
Document Center

Mobile Platform as a Service:Integrate Android SDK

Last Updated:Jun 28, 2023

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 be integrated to the mPaaS in the native AAR mode and the component mode.

Prerequisites

  • If you want to integrate 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 integrate the component to the mPaaS based on components, you need to first complete the Component-based integration 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.

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.

image.png

Configure the AndroidManifest.xml file

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

 <!--The AMAP positioning key-->
  <meta-data
        android:name="com.amap.api.v2.apikey"
        android:value="The AMAP positioning key that you applied for" />
  <!--The AMAP positioning service-->
  <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:

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

API description

  • Call the positioning service

    LBSLocationManagerProxy.getInstance().requestLocationUpdates(MainActivity.this, new LBSLocationListener() {
              @Override
              public void onLocationUpdate(LBSLocation lbsLocation) {
                  Toast.makeText(MainActivity.this, "lbsLocation is " + lbsLocation.getAddress(), Toast.LENGTH_LONG).show();
              }
              @Override
              public void onLocationFailed(int i) {
                  Toast.makeText(MainActivity.this,
                          "onLocationFailed" + i, Toast.LENGTH_SHORT).show();
              }
          });
  • Call other API operations

    // Register the location listener.
    public void requestLocationUpdates(Context context, LBSLocationListener locationListener)
    // Remove the callback of the location monitoring registration.
    public void removeUpdates(Context context, LBSLocationListener listener)
    // Obtain the location of the latest successful positioning.
    public LBSLocation getLastKnownLocation(Context context)