Magnus
Magnus

Reputation: 18810

Get a list of POIs (Points Of Interest) currently visible on a GoogleMap?

Using the Google Maps SDK, is it possible to get a list of all the POI's currently visible as "icons" on the map?

I know I can use the Places API to do something similar, but in my case I really just want to get the exact POI's that are currently visible as icons on the users screen at this moment.

I also know that I can listen for when the user taps on a POI, but this won't help in my case.

Upvotes: 0

Views: 552

Answers (1)

Andrii Omelchenko
Andrii Omelchenko

Reputation: 13353

Seems its impossible via Google Maps SDK, but anyway you can use workaround:

  1. Remove all "POI's currently visible as "icons" on the map" like in this answer of josef:

a) create JSON file src\main\res\raw\map_style.json like this:

[
  {
    featureType: "poi",
    elementType: "labels",
    stylers: [
      {
        visibility: "off"
      }
    ]
  }
]

b) add map style to your GoogleMap:

`googleMap.setMapStyle(MapStyleOptions.loadRawResourceStyle(getContext(), R.raw.map_style));`
  1. Get coordinates of area visible on screen:

    LatLngBounds visibleAreaBounds = googleMap.getProjection().getVisibleRegion().latLngBounds;

  2. Get information about POI's "manually" (by kinds of them) near screen center coordinates via Places SDK for Android and parse information about each place.

4.For each POI's coordinates check if it exactly inside bounds:

for (LatLng poiCoords : PoisCoords) {
    if (visibleAreaBounds.contains(poiCoords)) {
        // POI is visible on screen 
    }
}

Upvotes: 0

Related Questions