Getting Started

Note that we support Android 4.0 and higher. Goong SDK use open source from Mapbox community

Installation

Step 1: Download Goong-SDK-Android

Dependency

Add this in your root build.gradle file (not your module build.gradle file):

allprojects {
	repositories {
		...
    maven {
      url  "https://dl.bintray.com/goong-io/GoongMapSDK"
    }
	}
}

Then, add the library to your project build.gradle

dependencies {
  implementation('io.goong.goongsdk:goong-android-sdk:2.0.4'){
    transitive=true
  }
}

Simple Map

Step 2: Setup Goong Initialize Parse using your server configuration: Then to pass this into the Maps SDK, you’ll want to place the access token inside of your application’s onCreate() method.


public class MyApplication extends Application {

  @Override
  public void onCreate() {
    super.onCreate();

    // Goong Access token
    Goong.getInstance(getApplicationContext(), YOUR_GOONG_ACCESS_TOKEN);
  }
}

The custom Application class must be registered in AndroidManifest.xml:

 <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
 <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
 <application
   android:name=".Application"
   ...>
   ...
   <service android:name="io.goong.goongsdk.telemetry.TelemetryService" />
 </application>

Step 3: Hello Map! Take a look at the code

Examine the code supplied by the template. In particular, look at the following files in your Android Studio project.

The XML layout file

By default, the XML file that defines the app’s layout is at res/layout/activity_maps.xml. It contains the following code:

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/map"
    tools:context=".MapsActivity"
    android:name="io.goong.goongsdk.maps.SupportMapFragment" />

The maps activity Java file

By default, the Java file that defines the maps activity is named MapsActivity.java. It should contain the following code after your package name:

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {

    private GoongMap mMap;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_maps);
        SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);
    }

    @Override
    public void onMapReady(GoongMap goongMap) {
        mMap = goongMap;

        // Add a marker in Sydney, Australia, and move the camera.
        LatLng sydney = new LatLng(-34, 151);
        mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
        mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
    }
}

Tutorials

Map with Marker

Add a map

Display a map, using the Maps SDK for Android.

  • Add a <fragment> element to your activity’s layout file, activity_maps.xml. This element defines a SupportMapFragment to act as a container for the map and to provide access to the GoongMap object. The tutorial uses the Android support library version of the map fragment, to ensure backward compatibility with earlier versions of the Android framework.
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:id="@+id/map"
  android:name="io.goong.goongsdk.maps.SupportMapFragment"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  tools:context="com.example.mapwithmarker.MapsMarkerActivity" />
  • In your activity’s onCreate() method, set the layout file as the content view. Get a handle to the map fragment by calling FragmentManager.findFragmentById(). Then use getMapAsync() to register for the map callback:
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Retrieve the content view that renders the map.
    setContentView(R.layout.activity_maps);
    // Get the SupportMapFragment and request notification
    // when the map is ready to be used.
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);
}
  • Implement the OnMapReadyCallback interface and override the onMapReady() method, to set up the map when the GoongMap object is available:
public class MapsMarkerActivity extends AppCompatActivity
        implements OnMapReadyCallback {
    // Include the OnCreate() method here too, as described above.
    @Override
    public void onMapReady(GoongMap goongMap) {
        // Add a marker in Sydney, Australia,
        // and move the map's camera to the same location.
        LatLng sydney = new LatLng(-33.852, 151.211);
        goongMap.addMarker(new MarkerOptions().position(sydney)
                .title("Marker in Sydney"));
        goongMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
    }
}

By default, the Maps SDK for Android displays the content of the info window when the user taps a marker. There’s no need to add a click listener for the marker if you’re happy to use the default behavior.

Polylines and Polygons to Represent Routes and Areas

Add a polyline to draw a line on the map

A Polyline is a series of connected line segments. Polylines are useful to represent routes, paths, or other connections between locations on the map.

  • Create a PolylineOptions object and add points to it. Each point represents a location on the map, which you define with a LatLng object containing latitude and longitude values. The code sample below creates a polyline with 6 points.

  • Call GoongMap.addPolyline() to add the polyline to the map.

Make sure that the first and last Point locations are the same.

List<LatLng[]> points = new ArrayList<>();
points.add(new LatLng(-35.016, 143.321));
points.add(new LatLng(-34.747, 145.592));
points.add(new LatLng(-34.364, 147.891));
points.add(new LatLng(-33.501, 150.217));
points.add(new LatLng(-32.306, 149.248));
points.add(new LatLng(-32.491, 147.309));

goongMap.addPolyline(new PolylineOptions()
	.addAll(points)
	.color(Color.parseColor("#3bb2d0"))
	.alpha(0.5)
  .width(2));

Draw a polygon on the map

List<LatLng> polygonLatLngList = new ArrayList<>();
 
polygonLatLngList.add(new LatLng(45.522585, -122.685699));
polygonLatLngList.add(new LatLng(45.534611, -122.708873));
polygonLatLngList.add(new LatLng(45.530883, -122.678833));
polygonLatLngList.add(new LatLng(45.547115, -122.667503));
polygonLatLngList.add(new LatLng(45.530643, -122.660121));
polygonLatLngList.add(new LatLng(45.533529, -122.636260));
polygonLatLngList.add(new LatLng(45.521743, -122.659091));
polygonLatLngList.add(new LatLng(45.510677, -122.648792));
polygonLatLngList.add(new LatLng(45.515008, -122.664070));
polygonLatLngList.add(new LatLng(45.502496, -122.669048));
polygonLatLngList.add(new LatLng(45.515369, -122.678489));
polygonLatLngList.add(new LatLng(45.506346, -122.702007));
polygonLatLngList.add(new LatLng(45.522585, -122.685699));
 
goongMap.addPolygon(new PolygonOptions()
.addAll(polygonLatLngList)
.fillColor(Color.parseColor("#3bb2d0")));

Creating a map

Map Objects

Add a fragment

Add a <fragment> element to the activity’s layout file to define a Fragment object. In this element, set the android:name attribute to io.goong.goongsdk.maps.MapFragment. This automatically attaches a MapFragment to the activity.

The following layout file contains a <fragment> element:

<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
    android:name="io.goong.goongsdk.maps.MapFragment"
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

You can also add a MapFragment to an Activity in code. To do this, create a new MapFragment instance, and then call FragmentTransaction.add() to add the Fragment to the current Activity

mMapFragment = MapFragment.newInstance();
FragmentTransaction fragmentTransaction =
				getFragmentManager().beginTransaction();
				 fragmentTransaction.add(R.id.my_container, mMapFragment);
					fragmentTransaction.commit();

Add map code

To work with the map inside your app, you’ll need to implement the OnMapReadyCallback interface and set an instance of the callback on a MapFragment or MapView object. This tutorial uses a MapFragment, because that’s the most common way of adding a map to an app. The first step is to implement the callback interface:

public class MainActivity extends FragmentActivity
    implements OnMapReadyCallback {
    ...
    }

In your Activity’s onCreate() method, set the layout file as the content view. For example, if the layout file has the name main.xml, use this code:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    ...
}

Get a handle to the fragment by calling FragmentManager.findFragmentById(), passing it the resource ID of your <fragment> element. Notice that the resource ID R.id.map is added automatically to the Android project when you build the layout file.

Then use getMapAsync() to set the callback on the fragment.

MapFragment mapFragment = (MapFragment) getFragmentManager()
    .findFragmentById(R.id.map);
mapFragment.getMapAsync(this);

Use the onMapReady(GoongMap) callback method to get a handle to the GoongMap object. The callback is triggered when the map is ready to be used. It provides a non-null instance of GoongMap. You can use the GoongMap object to set the view options for the map or add a marker, for example.

@Override
public void onMapReady(GoongMap map) {
    map.addMarker(new MarkerOptions()
        .position(new LatLng(0, 0))
        .title("Marker"));
}

You can then add the attributes with a goong: prefix into your layout components, as you would with standard Android attributes.

The following XML code snippet shows how to configure a MapFragment with some custom options. The same attributes can be applied to a MapView as well.

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:map="http://schemas.android.com/apk/res-auto"
  android:name="io.goong.goongsdk.maps.SupportMapFragment"
  android:id="@+id/map"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  goong:goong_cameraTargetLat="-36.84"
  goong:goong_cameraTargetLng="174.76"
  goong:goong_cameraZoom="10"
  goong:goong_cameraBearing="34.33"
  goong:goong_cameraTilt="50.25"
  goong:goong_cameraZoomMax="12.41"
  goong:goong_cameraZoomMin="6"
  goong:goong_uiRotateGestures="false"/>

Styling the map

Your can custom style of the map when onMapReady

mapView.getMapAsync(new OnMapReadyCallback() {
@Override
    public void onMapReady(@NonNull final GoongMap goongMap) {
 
        goongMap.setStyle(Style.SATELLITE, new Style.OnStyleLoaded() {
            @Override
            public void onStyleLoaded(@NonNull Style style) {
                for (Layer singleLayer : goongMap.getStyle().getLayers()) {
                    Log.d(TAG, "onMapReady: layer id = " + singleLayer.getId());
                }
 
            }
        });
    }
});
Styles List
Style.GOONG_STREETS
Style.DARK
Style.SATELLITE
Style.NAVI_DAY
Style.NAVI_NIGHT
Style.UBAN

Interacting with the map

Events

Map click & long click events

Click (tap) events can be set up through the GoongMap object and invoke a callback each time that the event occurs. In both cases, the callback provides a LatLng of where the user click occurred on the map. To add an onClick listener to your map, insert the following snippet inside your application’s code:

goongMap.addOnMapClickListener(new GoongMap.OnMapClickListener() {
  @Override
  public void onMapClick(@NonNull LatLng point) {
   
    String string = String.format(Locale.US, "User clicked at: %s", point.toString())
     
    Toast.makeText(MainActivity.this, string, Toast.LENGTH_LONG).show();
   
  }
});

Convert from screen pixel

In occasions when you need to know the corresponding location on the screen where the user gesture occurred, you can convert the LatLng point to screen pixels. The GoongMap object provides the Projection from the map which allows you to convert between LatLng coordinates to screen pixel using goongMap.getProjection().toScreenLocation(<LatLng>);. The reverse is available when you have a screen location in pixels and need to convert it to a corresponding LatLng object.

A common use case for converting the values between LatLng and pixel coordinates is when you’d like to query a map layer or source to, for example, determine whether the users clicked on a POI.

Camera change events

The map’s camera is the view looking down on the maps flat plane. In almost all cases, you’ll be interacting with the camera to adjust the map’s starting zoom and target position. The user also can manipulate the camera by performing gestures on the map such as pinch-to-zoom, two-finger move to tilt, and single finger moves to adjust the position.

The Map SDK provides a handful of camera change listeners which can tell you of any or specific camera movements. The SDK gives different camera listeners to determine if the camera movement was caused by a user gesture, built-in API animations, or a developer-controlled movement. The snippet below shows the various camera listeners available:

goongMap.addOnCameraMoveStartedListener(new GoongMap.OnCameraMoveStartedListener() {

  private final String[] REASONS = {"REASON_API_GESTURE", "REASON_DEVELOPER_ANIMATION", "REASON_API_ANIMATION"};

  @Override
  public void onCameraMoveStarted(int reason) {
    String string = String.format(Locale.US, "OnCameraMoveStarted: %s", REASONS[reason - 1])
    Toast.makeText(MainActivity.this, string, Toast.LENGTH_LONG).show();
  }
});

goongMap.addOnCameraMoveListener(new GoongMap.OnCameraMoveListener() {
  @Override
  public void onCameraMove() {
    Toast.makeText(MainActivity.this, "onCameraMove", Toast.LENGTH_LONG).show();
  }
});

goongMap.addOnCameraMoveCancelListener(new GoongMap.OnCameraMoveCanceledListener() {
  @Override
  public void onCameraMoveCanceled() {
    Toast.makeText(MainActivity.this, "onCameraMoveCanceled", Toast.LENGTH_LONG).show();
  }
});

goongMap.addOnCameraIdleListener(new GoongMap.OnCameraIdleListener() {
  @Override
  public void onCameraIdle() {
    Toast.makeText(MainActivity.this, "onCameraIdle", Toast.LENGTH_LONG).show();
  }
});

On fling & on move events

Besides the camera change listeners, the GoongMap object allows you to listen into when the user moves or flings the map. A move event occurs when the user drags a single finger across the screen causing the camera position to change. A similar action from the user will cause the onFling callback to be invoked, but the user performs the gesture with more momentum. Only one of these events will be fired once when the user performs the particular gesture.

goongMap.addOnMoveListener(new GoongMap.OnMoveListener() {
  @Override
  public void onMoveBegin(MoveGestureDetector detector) {
    // user started moving the map
  }
  @Override
  public void onMove(MoveGestureDetector detector) {
    // user is moving the map
  }
  @Override
  public void onMoveEnd(MoveGestureDetector detector) {
    // user stopped moving the map
  }
});


goongMap.addOnFlingListener(new GoongMap.OnFlingListener() {
  @Override
  public void onFling() {
    Toast.makeText(MainActivity.this, "onFling", Toast.LENGTH_LONG).show();
  }
});

Marker and info window events

The Maps SDK provides a handy listener for capturing when a user taps on a marker. By default, all markers come with an onMarkerClick event listener for displaying and hiding info windows. You can override this default event listener and set your own with the setOnMarkerClickListener method.

To display a toast message with the clicked marker’s title, listen for a click event with setOnMarkerClickListener and finally call Toast.makeText(). To prevent displaying a toast message and an info window at the same time, return true at the end:

goongMap.setOnMarkerClickListener(new GoongMap.OnMarkerClickListener() {
  @Override
  public boolean onMarkerClick(@NonNull Marker marker) {
    Toast.makeText(MainActivity.this, marker.getTitle(), Toast.LENGTH_LONG).show();
    return true;
  }
});

In a similar case, the info window offers a handful of listeners for being notified when an info windows clicked, long clicked, or when a user closes the window.

goongMap.setOnInfoWindowLongClickListener(OnInfoWindowLongClickListener);
goongMap.setOnInfoWindowCloseListener(new GoongMap.OnInfoWindowCloseListener() {
  @Override
  public void onInfoWindowClose(@NonNull Marker marker) {

  }
});

goongMap.setOnInfoWindowClickListener(new GoongMap.OnInfoWindowClickListener() {
  @Override
  public boolean onInfoWindowClick(@NonNull Marker marker) {
    return false;
  }
});

Map change events

The MapView goes through a series of lifecycle events while building and changing the map. The Maps SDK provides many different change listener interfaces to tell you when a specific map event has occurred.

Instead of adding a listener to the GoongMap object, each listener is added to a MapView object. For example OnDidFinishRenderingMapListener and addOnDidFinishLoadingMapListener.

mapView.addOnDidFinishRenderingMapListener(new MapView.OnDidFinishRenderingMapListener() {
  @Override
  public void onDidFinishRenderingMap(boolean fully) {


  // The map has finished rendering

      
  }
});

You can also implement the specific change event interface and override its method. The interface callback is then invoked when a new map change occurs.

The listeners listed below are in the order in which the events occur during a MapView’s life.

Map change event listener Description
OnCameraWillChangeListener This event is triggered whenever the displayed map region is about to change without an animation.
OnCameraDidChangeListener This event is triggered whenever the displayed map region finished changing without an animation.
OnWillStartLoadingMapListener This event is triggered when the map is about to start loading a new map style.
OnWillStartRenderingMapListener This event is triggered when the map will start rendering the map.
addOnWillStartRenderingFrameListener This event is triggered when the map will start rendering a frame.
OnDidFinishRenderingFrameListener This event is triggered when the map finished rendering a frame.
OnCameraWillChangeListener This event is triggered whenever the displayed map region is about to change without an animation.
OnCameraDidChangeListener This event is triggered whenever the displayed map region finished changing without an animation.
OnDidFinishLoadingStyleListener Triggered when a style has finished loading.
OnDidFinishRenderingFrameListener This event is triggered when the map finished rendering a frame.
OnSourceChangedListener Triggered when a source changes.
addOnWillStartRenderingFrameListener This event is triggered when the map will start rendering a frame.
OnDidFinishRenderingFrameListener This event is triggered when the map finished rendering a frame.
OnDidFinishLoadingMapListener This is triggered when the map has successfully loaded a new map style.
addOnWillStartRenderingFrameListener This event is triggered when the map will start rendering a frame.
OnDidFinishRenderingMapListener This event is triggered when the map is fully rendered.

Additional change events that are not part of the standard MapView lifecycle:

Map change event listener Description
OnCameraIsChangingListener This event is triggered whenever the displayed map region is changing.
OnCameraDidChangeListener This event is triggered whenever the displayed map region finished changing with an animation.
OnDidFailLoadingMapListener This event is triggered when the map has failed to load a new map style.

Any of the map change event interfaces can be removed from the MapView object as well.

addOnDidFinishLoadingStyleListener() is useful if you’re using runtime styling to change the Goong map style in real time. Here’s how you’d use the constant:

mapView.addOnDidFinishLoadingStyleListener(new MapView.OnDidFinishLoadingStyleListener() {
  @Override
  public void onDidFinishLoadingStyle() {
  
  // The map is now ready for other changes
  
  }
});

Camera and View

Camera position

The Maps SDK includes a CameraPosition class which comprises of the camera’s target, angle, zoom, and tilt. These APIs shape the user’s perspective of the map tile(s).

A CameraPosition object can change a single property of the camera object such as the zoom, or it can change multiple properties at the same time. For example, you could write code to have the camera change its target, zoom out, and tilt all at the same time:

CameraPosition position = new CameraPosition.Builder()
  .target(new LatLng(51.50550, -0.07520))
  .zoom(10)
  .tilt(20)
  .build();

Update the camera position

The GoongMap class in the Maps SDK has several methods to change the camera’s position. Each camera movement API takes in a CameraUpdate object. You should use the CameraUpdateFactory class to provide the new camera position information. CameraUpdateFactory can build several different CameraUpdate objects including a newLatLngZoom(), zoomBy(), newLatLngBounds(), and several more. A straightforward method in CameraUpdate is newCameraPosition() which is how you’d pass in a built CameraPosition.

goongMap.animateCamera(CameraUpdateFactory.newCameraPosition(position), millisecondSpeed);

Aside from consuming a Camera Update object, a cancelable callback can be added to know when the animation finishes or if the user cancels the camera move by performing a gesture on the map. The ease and animate APIs have an optional duration parameter (in milliseconds) that lets you control the camera’s animation duration.

API Description
moveCamera() Repositions the camera according to the instructions defined in the update and moves the camera instantaneous. It’s recommended to avoid this API in favor of either the ease or animate camera APIs which will provide more context to your users where on the map the camera is positioning itself.
easeCamera() Gradually move the camera by the default duration, the zoom will not be affected unless specified within CameraUpdate. If you plan to have the map camera track the current user as they move this is the correct API to use since one of the parameters can be set to false, Disabling the animation interpolator and resulting in a linear ease animation.
animateCamera() Animate the camera to a new location defined within CameraUpdate using a transition animation that evokes powered flight.

Get the current camera position

The GoongMap class’ getCameraPosition() method helps your code understand what is going on with your map’s camera and what the user’s viewing. The method returns a CameraPosition object, and once you have the object, you can get and use the camera’s target, tilt, zoom, and bearing values. For example, goongMap.getCameraPosition().zoom is how you would get the camera’s current zoom value.

Center the camera within a map area

Like how a camera can be restricted to a region (see below), the camera can also center within a map area. First you’ll need a defined LatLngBounds object which includes at least two coordinates. You’ll then be able to update the camera position using the available newLatLngBounds() API which takes your bounding box and adjust the viewport so the specified region will be within view. Besides the bounding box being passed into the camera update factory, you will also need to provide an integer value defining the padding between the edge of the screen and the actual bounded region. You also have the option to provide different padding values for each side of the box.


LatLngBounds latLngBounds = new LatLngBounds.Builder()
                    .include(first marker position)
                    .include(second marker position)
                    .build();

goongMap.animateCamera(CameraUpdateFactory.newLatLngBounds(latLngBounds, 10));

Location data

You can use the My Location layer and the My Location button to show your user their current position on the map. Call mMap.setMyLocationEnabled() to enable the My Location layer on the map.

public class MyLocationDemoActivity extends FragmentActivity
    implements OnMapReadyCallback {

  private GoongMap mMap;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.my_location_demo);

    SupportMapFragment mapFragment =
        (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);
  }

  @Override
  public void onMapReady(GoongMap map) {
    mMap = map;
    // TODO: Before enabling the My Location layer, you must request
    // location permission from the user. This sample does not include
    // a request for location permission.
    mMap.setMyLocationEnabled(true);
  }
}

Building 3D

You can showing building with 3D in the map with GoongMap.setBuildingsEnabled(true).

public class MyLocationDemoActivity extends FragmentActivity
    implements OnMapReadyCallback {

  private GoongMap mMap;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.my_location_demo);

    SupportMapFragment mapFragment =
        (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);
  }

  @Override
  public void onMapReady(GoongMap map) {
    mMap = map;
    mMap.setBuildingsEnabled(true);
  }
}

Drawing on the map

Markers

This episode of Maps Live covers the basics of adding markers to your map using the Maps SDK for Android.

Add a marker

The following example demonstrates how to add a marker to a map. The marker is created at coordinates 10,10, and displays the string ‘Hello world’ in an info window when clicked.

@Override
public void onMapReady(GoongMap map) {
    map.addMarker(new MarkerOptions()
        .position(new LatLng(10, 10))
        .title("Hello world"));
}

Removing markers

The Goong Android SDK comes with two methods for removing markers. If you’d like to remove a particular marker, use goongMap.removeMarker() while passing in the marker object to be removed. If you would like to remove all markers, call the goongMap.clear() method. Note that this will also remove any polylines and polygons you’ve added to your map.

Customize marker icon

You can specify a custom icon by using the IconFactory object and passing it to the marker. The default marker icon’s used if you don’t specify an icon while creating your marker. The anchoring of the marker will be in the center, meaning if you have an icon with a point, you’ll need to add padding to the bottom of the image.

Place your custom marker image in your project’s drawable folder and note its file name. In the example below, the custom icon’s image file’s called blue_marker.png


// Create an Icon object for the marker to use
IconFactory iconFactory = IconFactory.getInstance(MainActivity.this);
Icon icon = iconFactory.fromResource(R.drawable.blue_marker);

// Add the marker to the map
goongMap.addMarker(new MarkerViewOptions()
  .position(new LatLng(-37.821648, 144.978594))
  .icon(icon));

Capturing marker events

The Goong Maps SDK for Android provides a handy listener for capturing when a user taps on a marker. By default, all markers come with an onMarkerClick event listener for displaying and hiding info windows. You can override this default event listener and set your own with the setOnMarkerClickListener method.

To display a toast message with the clicked marker’s title, listen for a click event with setOnMarkerClickListener and finally call Toast.makeText(). To prevent displaying a toast message and an info window at the same time, return true at the end:

goongMap.setOnMarkerClickListener(new GoongMap.OnMarkerClickListener() {
  @Override
  public boolean onMarkerClick(@NonNull Marker marker) {

  // Show a toast with the title of the selected marker
    Toast.makeText(this, marker.getTitle(), Toast.LENGTH_LONG).show();
    return true;
  }
});

Update a marker

// Change the marker location
marker.setPosition(new LatLng(-37.822884, 144.981916));

// Update the marker icon
marker.setIcon(icon);