To display the user's current location on the map, your application must first request and obtain location permissions from the user.
This is required to activate the location component. This method should be required before calling any locationComponent functions
val locationComponentActivationOptions =
LocationComponentActivationOptions.builder(this, style)
.build()
val locationComponent = mapplsMap.locationComponent
locationComponent?.activateLocationComponent(locationComponentActivationOptions)LocationComponentActivationOptions locationComponentActivationOptions =
LocationComponentActivationOptions.builder(this, style)
.build();
LocationComponent locationComponent = mapplsMap.getLocationComponent();
if(locationComponent != null) {
locationComponent.activateLocationComponent(locationComponentActivationOptions);
}To check the LocationComponent is activated or not. This check should be recomended to use before calling any LocationComponent function.
val isActivated = locationComponent.isLocationComponentActivatedboolean isActivated = locationComponent.isLocationComponentActivated();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.
locationComponent.isLocationComponentEnabled = truelocationComponent.setLocationComponentEnabled(true);The properties and location icon can change by LocationComponentOptions
- During Activation of
LocationComponentval locationComponentOption = LocationComponentOptions.builder(this) .backgroundDrawable(drawable) .build() val locationComponentActivationOptions = LocationComponentActivationOptions.builder(this, style) .locationComponentOptions(locationComponentOption) .build() val locationComponent = mapplsMap.locationComponent locationComponent?.activateLocationComponent(locationComponentActivationOptions)
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
LocationComponentval locationComponentOption = LocationComponentOptions.builder(this) .backgroundDrawable(drawable) .build() locationComponent.applyStyle(locationComponentOptions)
LocationComponentOptions locationComponentOptions = LocationComponentOptions.builder(DemoActivity.this) .backgroundDrawable(drawable) .build(); locationComponent.applyStyle(locationComponentOptions);
The LocationComponentOptions.Builder provides several customizable properties to configure the appearance and behavior of the location indicator on the map:
accuracyAlpha– Sets the opacity of the accuracy circle around the user's location.accuracyColor– Sets the solid color used to represent the location accuracy circle.backgroundDrawable– Sets the background icon for the location marker.backgroundDrawableStale– Sets the background icon for the stale state (when GPS is unavailable or outdated).foregroundDrawable– Sets the foreground icon for the active location marker.foregroundDrawableStale– Sets the stale foreground icon, indicating outdated location information.gpsDrawable– Sets the icon for navigation state (RenderMode.GPS), typically a directional marker.gpsStaleDrawable– Sets the stale GPS icon for navigation state when location updates are unavailable.bearingTintColor– Sets the tint color applied to the bearing indicator icon.
LocationEngine being used for updating the user location
val locationEngine = locationComponent?.locationEngineLocationEngine locationEngine = locationComponent.getLocationEngine();To get the recent current Location available:
- Using
LocationComponentval location = locationComponent.lastKnownLocation
Location location = locationComponent.getLastKnownLocation();
- Using
LocationEnginelocationEngine?.getLastLocation(object : LocationEngineCallback<LocationEngineResult?> { override fun onSuccess(locationEngineResult: LocationEngineResult?) { val location = locationEngineResult?.lastLocation } override fun onFailure(e: Exception) { } })
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
locationis the AndroidLocationobject. For more details please refer the documentation
To request continuous location update
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)
}
}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);
}
}Contains the variety of camera modes which determine how the camera will track the user location.
locationComponent.cameraMode = CameraMode.NONElocationComponent.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 GPSLocationbearing.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 normalizedLocation#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
Contains the variety of ways the user location can be rendered on the map.
locationComponent.renderMode = RenderMode.NORMALlocationComponent.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 theLocationupdates being provided to theLocationComponent.
For any queries and support, please contact:
Email us at apisupport@mappls.com
Support
Need support? contact us!
