因此,即时通讯尝试在jquerymobile中构建一个简单的“商店位置”服务,在一个屏幕中,使用谷歌地图制作所有商店的列表并显示距离当前位置的距离API。使用Google地图距离矩阵返回距离功能
我一直在寻找这个例子: http://code.google.com/apis/maps/documentation/javascript/examples/distance-matrix.html
从至极我使用下面的代码:
function calculateDistances() {
var service = new google.maps.DistanceMatrixService();
service.getDistanceMatrix(
{
origins: [origin1, origin2],
destinations: [destinationA, destinationB],
travelMode: google.maps.TravelMode.DRIVING,
unitSystem: google.maps.UnitSystem.METRIC,
avoidHighways: false,
avoidTolls: false
}, callback);
}
function callback(response, status) {
if (status != google.maps.DistanceMatrixStatus.OK) {
alert('Error was: ' + status);
} else {
var origins = response.originAddresses;
var destinations = response.destinationAddresses;
var outputDiv = document.getElementById('outputDiv');
outputDiv.innerHTML = '';
for (var i = 0; i < origins.length; i++) {
var results = response.rows[i].elements;
for (var j = 0; j < results.length; j++) {
outputDiv.innerHTML += origins[i] + " to " + destinations[j]
+ ": " + results[j].distance.text + " in "
+ results[j].duration.text + "<br />";
}
}
}
}
它的工作原理确定,因为它填充#outputDiv与所需的信息。 现在,我坚持如何使用calculateDistances()来填充每个div所属的每个存储区!我不明白如何返回上述函数的结果,因为回调()已经定义var outputDiv = document.getElementById('outputDiv');
到现在只适用于1格... 我需要做什么,以便每次我调用calculateDistances(),它填充我想要的div?
谢谢你们
谢谢Aleks :) – pedrosss