0
거리에 따라 별도로 원가 계산을해야하는 다중 경로가 있기 때문에 for 루프에서 Google지도를 호출합니다.For 루프가 돌아 오지 않는 루프 내에서 Google지도 호출
거리가 경로 중 하나에서만 반환된다는 점을 제외하면 모든 것이 효과가 있습니다.
지도에 대한 아약스 호출에서 선언 한 항목의 방식과 관련이 있다는 느낌이 들었습니다. 어떤 아이디어가 아래의 코드에서 문제가 될 수 있습니까?
for (var i = 1; i <= numJourneys; i++) {
var mapContainer = 'directionsMap' + i;
var directionContainer = $('#getDistance' + i);
$.ajax({
async: false,
type: "POST",
url: "Journey/LoadWayPoints",
data: "{'args': '" + i + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
if (msg.d != '[]') {
var map = new GMap2(document.getElementById(mapContainer));
var distance = directionContainer;
var wp = new Array();
//routes
var counter = 0;
$.each(content, function() {
wp[counter] = new GLatLng(this['Lat'], this['Long']);
counter = counter + 1;
});
map.clearOverlays();
map.setCenter(wp[0], 14);
// load directions
directions = new GDirections(map);
GEvent.addListener(directions, "load", function() {
alert(directions.getDistance());
//directionContainer.html(directions.getDistance().html);
});
directions.loadFromWaypoints(wp, { getSteps: true });
}
}
});
}