Question

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
}
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top