Jquery Google Map Api未捕获类型错误:无法读取null的属性“0”
我面临未捕获的TypeError问题:在将地址转换为纬度和经度时,无法读取null的属性“0”。这是我的代码 代码是Jquery Google Map Api未捕获类型错误:无法读取null的属性“0”,jquery,google-maps-api-3,Jquery,Google Maps Api 3,我面临未捕获的TypeError问题:在将地址转换为纬度和经度时,无法读取null的属性“0”。这是我的代码 代码是 function convertAddress( address, callback, item ) { geocoder.geocode( { 'address' : address }, function(results, status) { if ( status == google.maps.GeocoderStatus
function convertAddress( address, callback, item ) {
geocoder.geocode( {
'address' : address
}, function(results, status) {
if ( status == google.maps.GeocoderStatus.OK ) {
callback( results[0].geometry.location );
}
cords = [ results[0].geometry.location.pb, results[0].geometry.location.qb ];
$.post( jobifySettings.ajaxurl, { action : 'jobify_cache_cords', cords : cords, job : item.job } );
});
}
不要使用未记录的属性location.pb,location.qb
不要将依赖于成功结果的代码放在成功检查之外
function convertAddress( address, callback, item ) {
geocoder.geocode( {
'address' : address
}, function(results, status) {
if ( status == google.maps.GeocoderStatus.OK ) {
callback( results[0].geometry.location );
cords = [ results[0].geometry.location.lat(), results[0].geometry.location.lng() ];
$.post( jobifySettings.ajaxurl, { action : 'jobify_cache_cords', cords : cords, job : item.job } );
} else alert("Geocode failed, status: "+status);
});
}
如果您没有业务帐户,它还可能给您以下错误,该错误来自服务器的此响应:
{
"error_message" : "You have exceeded your rate-limit for this API.",
"results" : [],
"status" : "OVER_QUERY_LIMIT"
}
这意味着要么你一天加载api的次数太多/太集中,要么你试图加载很多地址
此特定响应也会导致此错误
Uncaught TypeError: Cannot read property 'geometry' of undefined
在这里你可以找到一些可能有用的提示。
您对坐标使用了错误的值。您必须使用结果[0].geometry.location.lat和结果[0].geometry.location.lng,而不是不时更改的内部结构属性。和可变跳线:不清楚在何处定义。