• Optimization
  • Navigation
  • Tracking
  • Maps
  • Places

Custom Location Pulsing Symbol

This example shows how to Custom Location Pulsing Style

  • Location Permissions Handling

  • Tracking current location automatically when Map ready

  • Custom location pulsing style

    • pulseColor

    • pulseSingleDuration

    • Enable/Disable pulsing

    • pulseMaxRadius

    • pulseAlpha

Custom Location Pulsing Symbol

For all code examples, refer to Android Maps SDK Code Examples

activity_customized_location_pulsing_circle.xml view source

1<?xml version="1.0" encoding="utf-8"?>
2<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 xmlns:app="http://schemas.android.com/apk/res-auto"
4 xmlns:tools="http://schemas.android.com/tools"
5 android:layout_width="match_parent"
6 android:layout_height="match_parent">
7
8 <ai.nextbillion.maps.core.MapView
9 android:id="@+id/mapView"
10 android:layout_width="match_parent"
11 android:layout_height="match_parent"
12 android:layout_marginBottom="0dp"
13 app:layout_constraintBottom_toTopOf="@+id/linearLayout"
14 app:layout_constraintLeft_toLeftOf="parent"
15 app:layout_constraintRight_toRightOf="parent"
16 app:layout_constraintTop_toTopOf="parent"
17 app:nbmap_uiAttribution="false" />
18

CustomizedLocationPulsingCircleActivity view source

1package ai.nextbillion;
2
3import android.annotation.SuppressLint;
4import android.graphics.Color;
5import android.location.Location;
6import android.os.Bundle;
7import android.view.Menu;
8import android.view.MenuItem;
9import android.view.animation.DecelerateInterpolator;
10import android.view.animation.Interpolator;
11import android.widget.ArrayAdapter;
12import android.widget.Button;
13import android.widget.Toast;
14
15import java.util.ArrayList;
16import java.util.List;
17
18import ai.nextbillion.maps.camera.CameraUpdateFactory;

The given code is an Android activity that demonstrates how to customize the pulsing circle of the location component on a map. The activity allows the user to change the duration and color of the pulsing circle.

initMapView:

  • The onCreate method initializes the mapView by finding the view from the layout file and calling onCreate on it.

  • The onMapReady method is implemented to handle the map when it is ready for use.

  • The mapView is initialized by calling getMapAsync and passing the activity itself as the callback.

handle Location Permissions:

  • The checkPermissions method checks if location permissions are granted. If permissions are granted, it calls getMapAsync to initialize the map.

  • If permissions are not granted, it creates a PermissionsManager and requests location permissions.

  • The PermissionsListener interface is implemented to handle the result of the permission request.

track the current location automatically when the map is ready:

  • The onMapReady method is called when the map is ready.

  • It sets the map style using the setStyle method, passing the desired style and a callback for when the style is loaded.

  • The locationComponent is obtained from the nextbillionMap object, and location component options are built.

  • The location component is activated and enabled, and the camera mode is set to tracking.

  • The last known location is forced to update if available.

customize the location pulsing style:

  • The buildLocationComponentOptions method is used to build the options for the location component.

  • It takes the pulsing circle color and duration as parameters and sets the desired properties for the location component options.

  • The setNewLocationComponentOptions method is called to update the location component options with new pulsing duration and color.

  • The following properties are adjusted to customize the example's pulsing circle UI:

    • DEFAULT_LOCATION_CIRCLE_PULSE_DURATION_MS: The default duration in milliseconds for the pulsing circle animation.

    • SECOND_LOCATION_CIRCLE_PULSE_DURATION_MS: The duration in milliseconds for the second pulsing circle animation.

    • THIRD_LOCATION_CIRCLE_PULSE_DURATION_MS: The duration in milliseconds for the third pulsing circle animation.

    • DEFAULT_LOCATION_CIRCLE_PULSE_RADIUS: The default radius of the pulsing circle.

    • DEFAULT_LOCATION_CIRCLE_PULSE_ALPHA: The default alpha value of the pulsing circle.

    • DEFAULT_LOCATION_CIRCLE_INTERPOLATOR_PULSE_MODE: The default interpolator for the pulsing circle animation.

    • DEFAULT_LOCATION_CIRCLE_PULSE_FADE_MODE: The default fade mode for the pulsing circle animation.

The color, duration and other properties of the pulsing circle can be changed by interacting with buttons and dialog menus in the activity. The onOptionsItemSelected method handles the button clicks and updates the location component accordingly.

Have Questions ?