解码出错了。。没有返回results,一般都要先判断status参数先把 geocoder = new google.maps.Geocoder();
geocoder.geocode({ 'address': 'abcde' }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location); } else {
alert("Geocode was not successful for the following reason: " + status);
}
});
geocoder.geocode({ 'address': 'abcde' }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location); } else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}else{
alert("Error:"+status);
} 代码中存在判断返回结果是否成功,而且电脑本机运行会有判断结果。放到服务器端就会直接报错误。
var geocoder = new google.maps.Geocoder();
if (geocoder) {
geocoder.geocode
({
address:addressStr
},
function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var dataJsonArray = new Array();
for (var i = 0; i < results.length; i++) {
var tempData = {
lat: results[i].geometry.location.lat(),
lng: results[i].geometry.location.lng(),
name: results[i].formatted_address };
dataJsonArray.push(tempData);
}
}
else {
//没有搜索到相应的地方
alert("没找到地方- -!");
}
});
}先判断status,然后读取lat、lng、name值。
for (var i = 0; i < results.length; i++) {
var tempData = {
lat: results[i].geometry.location.lat(),
lng: results[i].geometry.location.lng(),
name: results[i].formatted_address };
dataJsonArray.push(tempData);
}
测试结果显示dataJsonArray长度为1,但我同一时间请求次数比较多,最后提示我“OVER_QUERY_LIMIT”。所以“results is not define”是否是查询次数限制导致呢?如果必须请求多次,有什么方法可以解决此问题?