All Products
Search
Document Center

Mobile Platform as a Service:Integrate Android SDK

Last Updated:Nov 21, 2024

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

Note

By default, it is positioned at the district and county level. For detailed street levels, please refer to Other related API.

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();
          }
      });

Other related API

/**
* Registration positioning, positioning to district and county level
*/
public void requestLocationUpdates(Context context, LBSLocationListener locationListener)
/**
* Register positioning, if you need to position to street level, please use this API
* gpsEnable: False means positioning to the district and county level, true means positioning to the street level, which is more accurate and consumes more performance.
* miniInterval: Positioning interval period, you can use LBSLocationManagerProxy.DEFAULT_LOCATION_INTERVAL
* overtime: Positioning timeout period, you can use LBSLocationManagerProxy.LOCATION_TIME_OUT
* isNeedAddress: true means reverse geography, false means only latitude and longitude
* bizType: Business type, just pass null
*/
public void doRequestLocationUpdates(Context context, boolean gpsEnable, LBSLocationListener locationListener, long miniInterval, long overtime, boolean isNeedAddress, String bizType)
// Remove positioning registration callback
public void removeUpdates(Context context, LBSLocationListener listener)
// Obtain the location of the latest successful positioning
public LBSLocation getLastKnownLocation(Context context)