How to constantly detect nearby marker locations from current location in Google Maps android?

前提是你 提交于 2019-11-28 10:12:53

Short answer location.distanceTo(anotherLocation)

In setupMap i recommend to add additional listener, to get all location changes in a simple way.

mMap.setMyLocationEnabled(true);
mMap.setOnMyLocationChangeListener(this);

Then in this listener you just take distance between current location and your targets. Distance in meters.

@Override
public void onMyLocationChange(Location location) {
    Location target = new Location("target");
    for(LatLng point : new LatLng[]{POINTA, POINTB, POINTC, POINTD}) {
        target.setLatitude(point.latitude);
        target.setLongitude(point.longitude);
        if(location.distanceTo(target) < METERS_100) {
            // bingo!
        }
    }
}

Of course, you should make your activity implements GoogleMap.OnMyLocationChangeListener

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!