1

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)?

Alkhemeia
  • 13
  • 5

2 Answers2

2

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!

xomena
  • 31,125
  • 6
  • 88
  • 117
-1

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

Shahin
  • 391
  • 3
  • 9
  • Hey Shahin, with markers added by me manually it is working but not with these served from google. – Alkhemeia Sep 07 '19 at 12:56
  • well, that's because these markers are not Clickable at all. actually they shouldn't even be visible to you. did you add them by code? – Shahin Sep 07 '19 at 13:03