This is the code for calculating distance, real, through a dedicated service from Google:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
var origin; var destination; var url="http://maps.googleapis.com/maps/api/directions/xml?origin="+origin+"&destination="+destination+"&sensor=true"; // I use this source in Titanium Mobile. xhr = Titanium.Network.createHTTPClient(); xhr.open('GET',url); xhr.onload = function(){ // parse the XML var xml = this.responseXML; // find the steps in response var itemList = xml.documentElement.getElementsByTagName("step"); var itemListDistance = xml.documentElement.getElementsByTagName("distance").item(itemList.length).text; // check the real position of distance! var array = itemListDistance.split(" "); var distance = array[4].replace(/^\s*/, "").replace(/\s*$/, ""); }; xhr.send(); |
Its strong point is the accuracy of the distance even if the service only works if online.
Very great post. I just stumbled upon your blog and wished to say that I have really loved surfing around your weblog posts. After all I will be subscribing on your rss feed and I’m hoping you write once more soon!