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.

有帮助吗?

解决方案

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.

其他提示

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();
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top