0

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
}
Pradip
  • 3,189
  • 3
  • 22
  • 27

1 Answers1

0

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.

piotrpo
  • 12,398
  • 7
  • 42
  • 58
  • what means previously registered points? my previous location? – Nikita Grishko Sep 24 '13 at 11:54
  • i found this tutorial http://janmatuschek.de/LatitudeLongitudeBoundingCoordinates about calculating distance and one more here http://stackoverflow.com/questions/8049612/calculating-distance-between-two-geographic-locations, and i think better calculate distance by this method. – Nikita Grishko Sep 24 '13 at 13:39
  • it depends how accuracy in distance calculation is needed - n my own software, I just used simple flat geometry to get few nearest points (from track registering points every 1 sec.) and then used the Location class to confirm the result – piotrpo Sep 24 '13 at 13:44