Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compare two routes using google direction apis or some other apis for iPhone app

I want to compare two routes to check if they are same or not in my iPhone app.

There is a person X who wants to go to point A to point B and another person wants to go to point A1 to point B1.

I can get a route between A to B using this direction APIs of google.

http://maps.googleapis.com/maps/api/directions/xml?origin=Point a A address&destination=Point B address&sensor=false

same way I can get route of A1 to B1.

but the latitude and longitude I am getting in xmls are not matching (even a single point is not matching). So here is my question how can I match two routes I want to know is this same route or not.

enter image description here

like image 581
Saurabh Avatar asked Dec 27 '11 06:12

Saurabh


1 Answers

If the optimal route A1B1 is actually a subset of the route AB I'd expect the start_location and end_locations for the matching steps to share similar longitudes and latitudes, but this isn't a requirement of the directions API. The best path from A to B might pass through A1 and B1, but that doesn't mean the best path from A1 to B1 will share the exact same steps.

What I think you want to do is look at the polyline points returned for the route segments and see if they would pass through A1 and B1 in the correct order. You can expand the encoded polyline strings into a list of latitude and longitudes using this algorithm.

like image 83
bamnet Avatar answered Nov 10 '22 15:11

bamnet