androidgoogle-mapspoint-of-interest

Interact with Points of Interest on Google Maps


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


Solution

  • 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!