This may be a difficult question, I have a method in my map application that generates a distance between the user and the marker:
Thisdistanceismeasuredandupdatedsmoothlyaslongasthereisonly1markeronthemap:
privateLocationmarcadorLatLong(){Locationlocation=newLocation("PONTO_MARCADO");
LatLng posicao = new LatLng(29.9917493 , -51.0685212);
Marker marker2 = mMap.addMarker(new MarkerOptions()
.position(posicao)
.title("treste")
.visible(true));
location.setLatitude(posicao.latitude);
location.setLongitude(posicao.longitude);
return location;
}
public class MyLocationListener implements LocationListener {
public void onLocationChanged(Location location) {
Location pointLocation = marcadorLatLong();
float distance = location.distanceTo(pointLocation);
Toast.makeText(MapsActivity.this, "Distância do ponto:"+distance, Toast.LENGTH_SHORT).show();
if(distance <= 3){
if(posicao != 0)
{
posicao = 0;
}
mp.seekTo(posicao);
mp.start();
}
}
}
Now when the situation is with multiple markers:
The following event occurs, the distance selection is always with the last marker entered, and I need the distance selection always to be on that marker that is closest to the user.