状态零结果 google 地图 GeocoderStatus
status zero results google maps GeocoderStatus
我们需要在 Google maps.We 中的一些点之间绘制方向,但 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"
。请帮助 me.tell 我的 code.WE 有什么问题 json 然后 JSON 数据传递给我的json 变量。calcRoute
按钮操作中的方法调用。
当我们打印时 waypoints
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
从输出来看,您的 myjson(数组?)似乎有问题。
无论如何,当我尝试重现它时,它成功了。
//from how you use your myjson var, I would assume it looks something like this:
var myjson = [
{ Lattitude: 37.4184, Longitude: -122.0880 },
{ Lattitude: 37.7833, Longitude: -122.4167 },
{ Lattitude: 38.5539, Longitude: -121.7381 }
]
var waypts = [];
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
});
}
console.log(JSON.stringify(waypts));
var request = {
origin:waypts[0].location,
destination:waypts[waypts.length-1].location,
waypoints: waypts.slice(1, waypts.length-1),
//the example in the documentation does not include the start & end points
//that might be a problem https://developers.google.com/maps/documentation/javascript/directions#DirectionsRequests
optimizeWaypoints: true,
travelMode: google.maps.TravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});
打印时waypoints
[{"location":{"k":37.4184,"D":-122.08799999999997},"stopover":true},{"location":{"k":37.7833,"D":-122.41669999999999},"stopover":true},{"location":{"k":38.5539,"D":-121.73810000000003},"stopover":true}]
希望对您有所帮助
在我的例子中,数据来自 HTML li
元素,但它以字符串形式出现,即
coordsData = {
lat: {
value: "19.4921383",
someOtherProperties: {}
},
lng: {
value: "-99.04651999999999",
someOtherProperties: {}
}
}
所以,我必须像这样转换这些值:
var myCoords = new google.maps.LatLng(parseFloat(coordsData.lat.value), parseFloat(coordsData.lng.value))
以防万一有人遇到同样的问题。
我们需要在 Google maps.We 中的一些点之间绘制方向,但 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"
。请帮助 me.tell 我的 code.WE 有什么问题 json 然后 JSON 数据传递给我的json 变量。calcRoute
按钮操作中的方法调用。
当我们打印时 waypoints
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
从输出来看,您的 myjson(数组?)似乎有问题。
无论如何,当我尝试重现它时,它成功了。
//from how you use your myjson var, I would assume it looks something like this:
var myjson = [
{ Lattitude: 37.4184, Longitude: -122.0880 },
{ Lattitude: 37.7833, Longitude: -122.4167 },
{ Lattitude: 38.5539, Longitude: -121.7381 }
]
var waypts = [];
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
});
}
console.log(JSON.stringify(waypts));
var request = {
origin:waypts[0].location,
destination:waypts[waypts.length-1].location,
waypoints: waypts.slice(1, waypts.length-1),
//the example in the documentation does not include the start & end points
//that might be a problem https://developers.google.com/maps/documentation/javascript/directions#DirectionsRequests
optimizeWaypoints: true,
travelMode: google.maps.TravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});
打印时waypoints
[{"location":{"k":37.4184,"D":-122.08799999999997},"stopover":true},{"location":{"k":37.7833,"D":-122.41669999999999},"stopover":true},{"location":{"k":38.5539,"D":-121.73810000000003},"stopover":true}]
希望对您有所帮助
在我的例子中,数据来自 HTML li
元素,但它以字符串形式出现,即
coordsData = {
lat: {
value: "19.4921383",
someOtherProperties: {}
},
lng: {
value: "-99.04651999999999",
someOtherProperties: {}
}
}
所以,我必须像这样转换这些值:
var myCoords = new google.maps.LatLng(parseFloat(coordsData.lat.value), parseFloat(coordsData.lng.value))
以防万一有人遇到同样的问题。