我是 javascript 新手,我对 google 方向有这个问题:
我有一个表格,其中包含不同地方的坐标,例如:
lieux = [
{"nom": "place1", "icon": "galerie.png", "coordinates": [46.2018773, 6.1396896]},
{"nom": "place2", "icon": "galerie.png", "coordinates": [46.1989726, 6.1371983]},
{"nom": "place3", "icon": "galerie.png", "coordinates": [46.1976313, 6.1382951]},
{"nom": "place4", "icon": "galerie.png", "coordinates": [46.1997394, 6.1388766]}
];
我想为每个计算行程的地方创建方向按钮。这是计算路径的函数,它在初始化器()之外
function errorfunction(error){
console.log(error);
};
function successfunction(position){
myLatitude = position.coords.latitude;
myLongitude = position.coords.longitude;
};
calcul_itin = function() {
origin = myLatitude+","+myLongitude;
for (i = 0; i < place.length; i++) {
lieuxLat = place[i].coordinates[0];
lieuxLong = place[i].coordinates[1];
destination = placeLat+","+placeLong;
}
if(origin && destination){
var request = {
origin : origin,
destination : destination,
travelMode : google.maps.DirectionsTravelMode.WALKING
}
var directionsService = new google.maps.DirectionsService();
directionsService.route(request, function(response, status){
if(status == google.maps.DirectionsStatus.OK){
direction.setDirections(response);
}
});
};
};
但是,每个按钮都会计算表格最后一个位置的行程,我不知道如何安排我的代码来改变它。