javascript - get distance using google maps distance matrix api JSON output -


i developed following code distance of given 2 cities through 2 textfields , want send them google maps distance matrix api using following url. send cities , got json output file. problem how can specific attribute(distance) json file , display on textfield.

function m() {              var x = document.getelementbyid("autocomplete").value;             var y = document.getelementbyid("autocomplete1").value;              var url = "https://maps.googleapis.com/maps/api/distancematrix/json?origins=" + x + "&destinations=" + y + "&key=aizasyd5kx6vron6yq0vu4s6gsnavzazrwg8wrc";  window.location=url; // go above url , display json output file on browser. dont want shown. processing , should display distance form file on textfield!  } 

the json output file http://pastebin.ca/3318529

please solve this. new json. if have other ideas tell me. many :)

if use javascript in browser, need use google maps api.

check example:

<script src="https://maps.google.com/maps/api/js?sensor=false"></script> <script> function init() {   var service = new google.maps.distancematrixservice;   service.getdistancematrix({     origins: ['los angeles'],     destinations: ['new york'],     travelmode: google.maps.travelmode.driving,     unitsystem: google.maps.unitsystem.metric,     avoidhighways: false,     avoidtolls: false   }, function(response, status) {     if (status !== google.maps.distancematrixstatus.ok) {       alert('error was: ' + status);     } else {       alert(response.originaddresses[0] + ' --> ' + response.destinationaddresses[0] + ' ==> ' + response.rows[0].elements[0].distance.text);     }   }); } </script> <body onload="init()"> </body> 

running example https://jsfiddle.net/3b03m5mt/


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -