Question

I have google map which contains multiple markers. I want to alert when current location becomes close to each of these markers. How can I do that? Could you pls provide me with an example? Thx in advance.

Was it helpful?

Solution

The Geofencing API (part of the Google Play Location Services) "lets your app setup geographic boundaries around specific locations and then receive notifications when the user enters or leaves those areas" and is compatible with API 8+ devices. The first link contains all of the code needed to set up Geofencing on a number of locations.

OTHER TIPS

You must save your markers in one List, when LocationListener.onLocationChanged() will be called you will be able to compare your current location with markers location.

To get Market instance get it when add to map.

Marker marker = map.addMarker(new MarkerOptions()
     .position(new LatLng(37.7750, 122.4183))
     .title("San Francisco")
     .snippet("Population: 776733"));

To get LatLng.

marker.getPosition();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top