Skip to content

Show Current Location

To display the user's current location on the map, your application must first request and obtain location permissions from the user.

Activate Location Component

This is required to activate the location component. This method should be required before calling any locationComponent functions

Kotlin

val locationComponentActivationOptions =
LocationComponentActivationOptions.builder(this, style)
    .build()
val locationComponent = mapplsMap.locationComponent
locationComponent?.activateLocationComponent(locationComponentActivationOptions)

Java

LocationComponentActivationOptions  locationComponentActivationOptions =
        LocationComponentActivationOptions.builder(this, style)
                .build();
LocationComponent locationComponent = mapplsMap.getLocationComponent();
if(locationComponent != null) {
    locationComponent.activateLocationComponent(locationComponentActivationOptions);
}

Check Location Component is Activated

To check the LocationComponent is activated or not. This check should be recomended to use before calling any LocationComponent function.

Kotlin

val isActivated = locationComponent.isLocationComponentActivated

Java

boolean isActivated = locationComponent.isLocationComponentActivated();

Show/Hide Current Location On Map

Use this functionality to enable or disable the display of the user's current location on the map by controlling the visibility of the Location Component.

Kotlin

locationComponent.isLocationComponentEnabled = true

Java

locationComponent.setLocationComponentEnabled(true);

Change Location Icon

The properties and location icon can change by LocationComponentOptions - During Activation of LocationComponent #### Kotlin

    val locationComponentOption = LocationComponentOptions.builder(this)
        .backgroundDrawable(drawable)
        .build()
    val locationComponentActivationOptions =
        LocationComponentActivationOptions.builder(this, style)
            .locationComponentOptions(locationComponentOption)
            .build()
    val locationComponent = mapplsMap.locationComponent
    locationComponent?.activateLocationComponent(locationComponentActivationOptions)
#### Java
    LocationComponentOptions locationComponentOptions = LocationComponentOptions.builder(DemoActivity.this)
            .backgroundDrawable(drawable)
            .build();
    LocationComponentActivationOptions  locationComponentActivationOptions =
            LocationComponentActivationOptions.builder(DemoActivity.this, style)
                    .locationComponentOptions(locationComponentOptions)
                    .build();
    LocationComponent locationComponent = mapplsMap.getLocationComponent();
    if(locationComponent != null) {
        locationComponent.activateLocationComponent(locationComponentActivationOptions);
    }
  • After Activation of LocationComponent #### Kotlin
    val locationComponentOption = LocationComponentOptions.builder(this)
        .backgroundDrawable(drawable)
        .build()
    locationComponent.applyStyle(locationComponentOptions)
#### Java
    LocationComponentOptions locationComponentOptions = LocationComponentOptions.builder(DemoActivity.this)
            .backgroundDrawable(drawable)
            .build();
    locationComponent.applyStyle(locationComponentOptions);
LocationComponentOptions.Builder Properties :

The LocationComponentOptions.Builder provides several customizable properties to configure the appearance and behavior of the location indicator on the map:

  1. accuracyAlpha – Sets the opacity of the accuracy circle around the user's location.
  2. accuracyColor – Sets the solid color used to represent the location accuracy circle.
  3. backgroundDrawable – Sets the background icon for the location marker.
  4. backgroundDrawableStale – Sets the background icon for the stale state (when GPS is unavailable or outdated).
  5. foregroundDrawable – Sets the foreground icon for the active location marker.
  6. foregroundDrawableStale – Sets the stale foreground icon, indicating outdated location information.
  7. gpsDrawable – Sets the icon for navigation state (RenderMode.GPS), typically a directional marker.
  8. gpsStaleDrawable – Sets the stale GPS icon for navigation state when location updates are unavailable.
  9. bearingTintColor – Sets the tint color applied to the bearing indicator icon.

Get Location Engine

LocationEngine being used for updating the user location

Kotlin

val locationEngine = locationComponent?.locationEngine

Java

LocationEngine locationEngine = locationComponent.getLocationEngine();

Get Last Location

To get the recent current Location available: - Using LocationComponent #### Kotlin

    val location = locationComponent.lastKnownLocation
#### Java
    Location location = locationComponent.getLastKnownLocation();
  • Using LocationEngine #### Kotlin
    locationEngine?.getLastLocation(object :
        LocationEngineCallback<LocationEngineResult?> {
        override fun onSuccess(locationEngineResult: LocationEngineResult?) {
                val location = locationEngineResult?.lastLocation
        }
        override fun onFailure(e: Exception) {
        }
    })
#### Java
    locationEngine.getLastLocation(new LocationEngineCallback<LocationEngineResult>() {
        @Override
        public void onSuccess(LocationEngineResult locationEngineResult) {
            if(locationEngineResult != null && locationEngineResult.getLastLocation()) {
                Location location = locationEngineResult.getLastLocation();
            }
        }
        @Override
        public void onFailure(@NonNull Exception e) {
        }
    });

Note: Where location is the Android Location object. For more details please refer the documentation

Location Update Callback

To request continuous location update

Kotlin

val locationEngineCallback = object : LocationEngineCallback<LocationEngineResult> {
    override fun onSuccess(result: LocationEngineResult?) {
        if(result?.lastLocation != null) {
            val location = result.lastLocation
        }
    }

    override fun onFailure(e: Exception) {

    }
}
val request = LocationEngineRequest.Builder(1000)
    .setPriority(LocationEngineRequest.PRIORITY_HIGH_ACCURACY)
    .build()
// To add Location Update Listener
locationEngine?.requestLocationUpdates(request, locationEngineCallback, mainLooper)


// To remove Location Update Listener
override fun onDestroy() {
    super.onDestroy()
    if (locationEngine != null) {
        locationEngine?.removeLocationUpdates(locationEngineCallback)
    }
}

Java

LocationEngineCallback<LocationEngineResult> locationEngineCallback = new LocationEngineCallback<LocationEngineResult>() {
    @Override
    public void onSuccess(LocationEngineResult locationEngineResult) {
        if(locationEngineResult.getLastLocation() != null) {
            Location location = locationEngineResult.getLastLocation();
        }
    }

    @Override
    public void onFailure(@NonNull Exception e) {

    } 
};

LocationEngineRequest request = new LocationEngineRequest.Builder(DEFAULT_INTERVAL_IN_MILLISECONDS)
        .setPriority(LocationEngineRequest.PRIORITY_HIGH_ACCURACY)
        .build();
// To add Location Update Listener
locationEngine.requestLocationUpdates(request, locationEngineCallback, getMainLooper());

// To remove Location Update Listener
@Override
protected void onDestroy() {
  super.onDestroy();
    // Prevent leaks  
    if (locationEngine != null) {
        locationEngine.removeLocationUpdates(locationEngineCallback);
    }
}

Camera Mode

Contains the variety of camera modes which determine how the camera will track the user location.

Kotlin

locationComponent.cameraMode = CameraMode.NONE

Java

locationComponent.setCameraMode(CameraMode.NONE);

Following are the possible values for CameraMode: - CameraMode.NONE: No camera tracking. - CameraMode.NONE_COMPASS: Camera does not track location, but does track compass bearing. - CameraMode.NONE_GPS: Camera does not track location, but does track GPS Location bearing. - CameraMode.TRACKING: Camera tracks the device location, no bearing is considered. - CameraMode.TRACKING_COMPASS: Camera tracks the device location, tracking bearing provided by the device compass. - CameraMode.TRACKING_GPS: Camera tracks the device location, with bearing provided by a normalized Location#getBearing(). - CameraMode.TRACKING_GPS_NORTH: Camera tracks the device location, with bearing always set to north (0).

Note: On Slide the Map or if we call any Camera Controls Function then the Camera Mode is set to CameraMode.NONE

Render Mode

Contains the variety of ways the user location can be rendered on the map.

Kotlin

locationComponent.renderMode = RenderMode.NORMAL

Java

locationComponent.setRenderMode(RenderMode.NORMAL);

Following are the possible values for RenderMode: - RenderMode.NORMAL: This mode shows the device location, ignoring both compass and GPS bearing (no arrow rendered). - RenderMode.COMPASS: This mode shows the device location, as well as an arrow that is considering the compass of the device. - RenderMode.GPS: This mode shows the device location with the icon bearing updated from the Location updates being provided to the LocationComponent.

For any queries and support, please contact:

Email us at apisupport@mappls.com


Support
Need support? contact us!




@ Copyright 2025 CE Info Systems Ltd. All Rights Reserved.