1
This may be a difficult question, I have a method in my maps application that generates a distance between the user and the marker:
this distance is measured and updated smoothly as long as there is only 1 marker on the map:
private Location marcadorLatLong() {
Location location = new Location("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 inserted, and I need the distance selection to always be on that marker that is closest to the user.