How to check if my current location is on the route that i draw befor, and if not, redraw route

StackOverflow https://stackoverflow.com/questions/18980279

Frage

How to check if my current location is on the route that I draw before, and if not, redraw route.

So how I think: we have something like this:

ArrayList<LatLng> listGeopoints = new ArrayList<LatLng>()

(in response from

String url = "http://maps.googleapis.com/maps/api/directions/xml?" 
            + "origin=" + start.latitude + "," + start.longitude  
            + "&destination=" + end.latitude + "," + end.longitude 
            + "&sensor=false&units=metric&mode=driving";

)

and i have to make function something like this

for(LatLng point : listGeopoint){
    if (checkIfPointNearly(currentPoint, point)) return true;
     else return false
}
War es hilfreich?

Lösung

The basic way is - you have to check if your current position is near some of previously registered points Location class has a method to measure distance to other location.

For performance - you can adopt Pitagoras formula - just remember that degree of latitude is (quite) constant and the degree of longitude varies depending on current latitude length_of_longitude_degree = cos(latitude). Location distance (no sure name of this method) is based on some sophisticated geometry, "real" shape of earth etc. so it's not wise to use it against few thousands geo points.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top