Interact with Points of Interest on Google Maps

1.5k views Asked by At

I am working on Android Studio with the Maps Api. On the shown map, there are markers that have been already placed by Google (see picture below). enter image description here

Is there a way to interact with them by clicking to get more information (e.g. id of marker/place)?

2

There are 2 answers

0
xomena On BEST ANSWER

The predefined markers added by Google are called Points of Interest (POI). The GoogleMaps class provides a special listener for POIs: GoogleMap.OnPoiClickListener

You can find corresponding documentation in

https://developers.google.com/maps/documentation/android-sdk/reference/com/google/android/libraries/maps/GoogleMap.OnPoiClickListener

https://developers.google.com/maps/documentation/android-sdk/reference/com/google/android/libraries/maps/model/PointOfInterest

The code snippet should be something like

mMap.setOnPoiClickListener(new GoogleMap.OnPoiClickListener() {
    @Override
    public void onPoiClick(PointOfInterest poi) {
        String placeId = poi.placeId;
        //TODO: get details for place id
    });
}

I hope this helps!

2
Shahin On

you can use onMarkerClickListener shown below :

mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
    @Override
    public boolean onMarkerClick(Marker marker) {

    });
}

where mMap is an instance of GoogleMap

You can start reading documentation here https://developers.google.com/maps/documentation/android-sdk/start