我开发了以下代码以通过 2 个文本字段获取给定 2 个城市的距离,我想使用以下 URl 将它们发送到谷歌地图距离矩阵 api。我发送这些城市并获得 JSON 输出文件。但我的问题是如何从该 JSON 文件中获取特定属性(距离)并显示在另一个文本字段上。
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; // this will go to the above url and display the JSON output file on the browser. I dont want that to be shown. just some processing and should display only the distance form that file on a textfield!
}
JSON 输出文件http://pastebin.ca/3318529
请帮助解决这个问题。我是 JSON 新手。因此,如果您有任何其他想法,请告诉我。非常感谢 :)