3

I have polyline data in mysql. I want to measure its length in php. I have looked distance matrix api. But it requests origin_addresses and destination_addresses , i haven't got those values.

I found decodePolylineToArray gist but when i decode my polyline, there are a lot of values. How can i measure length of polyline? I am using php but if you have a method in another language, i can port it to php.

1 Answers1

0

You need to use Haversine's formula for every Path in the polyline: http://en.wikipedia.org/wiki/Haversine_formula

For different programming languages search for : https://www.google.ch/search?q=php+haversine+formula&aq=0&oq=php+Haversine&aqs=chrome.1.57j0l3j62l2.8586&sourceid=chrome&ie=UTF-8

This is a good sample for manual calculation in JS Calculate distance between two points in google maps V3, but there is a simpler way:

google.maps.geometry.spherical.computeDistanceBetween(path.getAt(i), path.getAt(i+1));

Check out this sample: http://www-users.mat.umk.pl/~kaskader/polyline_simple.html that uses it.

HTH

Community
  • 1
  • 1
kaskader
  • 1,931
  • 16
  • 24
  • Thanks for your answer. If i calculate distance with Haversine's formula, is it equal to Google maps native calculation? Yes, i know javascript have a lot of shortcut but i don't find easier solutions in web services api. – user1872364 Dec 03 '12 at 14:15
  • es. Using Haversine formula will give you the same results. What programming language do you need ? You basically would need to rewrite this: http://stackoverflow.com/a/1502821/1062708 – kaskader Dec 03 '12 at 14:46
  • It has worked. I used decodePolylineToArray gist and this gist http://pastebin.com/P711segA . Thank you so much. – user1872364 Dec 04 '12 at 07:22