Attention! Do you have any ideas for reorganizing and updating the Mapki? Please leave a note here. Thank you!
Polyline Decode
From Google Mapki
// Decode points to lat/long array // Author: Ian Dees 2005 // Help from: http://www.thrall.net/~mking/maps/points.py function decodePolyline( $a ) { $b = strlen($a); $c = 0; $d = Array(); $e = 0; $f = 0; while($c < $b) { $g = 0; $h = 0; $i = 0; do { $g = ord(substr($a,$c++,1)) - 63; $i |= ($g & 31) << $h; $h += 5; } while($g >= 32); $k = $i & 1 ? ~($i >> 1) : $i >> 1; $e += $k; $h = 0; $i = 0; do { $g = ord(substr($a,$c++,1)) - 63; $i |= ($g & 31) << $h; $h += 5; } while($g >= 32); $l = $i & 1 ? ~($i >> 1) : $i >> 1; $f += $l; array_push($d, Array('lat' => $e*1.0E-5, 'lon' => $f*1.0E-5)); } return $d; }
[edit] Problem
This code appears not to work for many large paths. I used it to get a path from the Google page: http://www.google.com/maps?f=d&hl=en&saddr=Austin,+tx&daddr=San+Antonio,+TX&sll=29.423889,-98.493333&sspn=0.211719,0.322037&ie=UTF8&z=10&om=1
And it comes up with a path along this instead: http://falazar.com/AI/GPS/austin_wrong_example.php
I have tested with a couple other texas cities to be sure as well.
Please send any updates to: falazar@yahoo.com
[edit] Solution
You must take into account that the coded string contains escape sequences (e.g. '\\' for '\').
