【发布时间】:2015-05-20 19:24:38
【问题描述】:
我们需要在 Google 地图中的某些点之间绘制方向。我们尝试过,但 DirectionsStatus 来自"zero results"。我们尝试过这样
function initialize() {
directionsDisplay = new google.maps.DirectionsRenderer();
var chicago = new google.maps.LatLng(41.850033, -87.6500523);
var mapOptions = {
zoom: 6,
center: chicago
}
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
directionsDisplay.setMap(map);
}
function calcRoute() {
debugger;
var waypts = [];
var checkboxArray = document.getElementById('waypoints');
for (var i = 0; i < myjson.length; i++) {
var data = myjson[i];
waypts.push({
location: new google.maps.LatLng(parseFloat(myjson[i].Lattitude), parseFloat(myjson[i].Longitude)),
stopover: true
});
}
debugger;
console.log(waypts);
var request = {
origin:waypts[0].location,
destination:waypts[waypts.length-1].location,
waypoints: waypts,
optimizeWaypoints: true,
travelMode: google.maps.TravelMode.DRIVING
};
debugger;
directionsService.route(request, function(response, status) {
debugger;
if (status == google.maps.DirectionsStatus.OK) {
debugger;
directionsDisplay.setDirections(response);
var route = response.routes[0];
}
});
}
我们需要状态码"OK"。请帮帮我。告诉我我的代码出了什么问题。我们有 json,然后 JSON 数据传递给 Myjson 变量。calcRoute 按钮操作中的方法调用。
当我们打印航点时
Array[6]0: Objectlocation: kfD: 78.54940429999999k: 17.4211137__proto__: kfstopover: true__proto__: Object1: Objectlocation: kfstopover: true__proto__: Object2: Objectlocation: kfstopover: true__proto__: Object3: Object4: Object5: Objectlength: 6
【问题讨论】:
-
当您提醒
waypts(或console.log())时,它会是什么样子? -
@duncan waypts like this 0: Object location: kf D: 78.54940429999999 k: 17.4211137 proto: kf stopover: true proto: Object 1:对象 2:对象 3:对象
-
呃...看起来不像一个数组,但很难从该评论中看出。如果您执行 console.log() ,您能否准确地更新您的答案?
-
@duncan 是的,我们更新代码开玩笑我们打印航点
标签: javascript google-maps cordova google-maps-api-3 geolocation