Friday, 15 April 2011

jquery - Using ajax and json to ge the driving distance between two addresses -



jquery - Using ajax and json to ge the driving distance between two addresses -

is possible utilize jquery ajax function , google directions api asynchronous calculate distance in miles between 2 given addresses? i've found few examples show how using php, nil doesn't require page reload

yes implement calculation in php, , phone call script asynchronously using ajax:

$.ajax({ url: "calcdist.php?address1="+addr1+"&address2="+addr2, success: function(result){ alert("distance "+result+" miles); } });

and in script (calcdist.php):

<?php $a1 = $_get['address1']; $a2 = $_get['address2']; $ll1 = getlatlong($a1); $ll2 = getlatlong($a2); $dist = haversine($ll1, $ll2); echo $dist; ?>

you need implement haversine , getlatlong functions in php

see haversine formula php + http://code.google.com/p/gogeocode/ help these

jquery api google-maps distance directions

No comments:

Post a Comment