【发布时间】:2020-09-13 08:38:03
【问题描述】:
在下表的代码中,locs 包含了来自希腊不同地区的一些名称。对于每个区域,我调用 graphicMap 函数 来通过 Geocoding Service 查找纬度和经度并在地图上创建标记。
但是从索引 12 开始,它显示错误。
查看以下结果:
错误:ΧΑΝΙΩΝ
OK : ΑΝΔΡΑΒΙΔΑΣ - ΚΥΛΛΗΝΗΣ
好的:ΒΕΡΟΙΑΣ
好的:AΒΔΗΡΩΝ
好的:ΑΧΑΡΝΩΝ
好的:ΑΣΤΥΠΑΛΑΙΑΣ
好的:ΡΕΘΥΜΝΗΣ
好的:ΓΑΛΑΤΣΙΟΥ
好的:ΔΕΛΦΩΝ
好的:ΒΕΛΒΕΝΤΟΥ
好的:ZΑΓΟΡΑΣ - ΜΟΥΡΕΣΙΟΥ
好的:ΒΕΛΟΥ ΒΟΧΑΣ
如果我删除例如记录 ΑΧΑΡΝΩΝ,ΧΑΝΙΩΝ 的值正常工作。
谷歌是否对通过地理编码服务的搜索设置了限制?
这是因为我没有购买 API KEY 吗?
提前致谢!
geocodeLatLong( JXMapContent , map , mapSet , graphic , graph , pins ){
/**
**** @procedure
**** Split and create table with the regions
**** Iterate table and find coordinates for each region
**/
var locs = JXMapContent.split( "," ) , u , length_table = locs.length;
for( u = 0; u < length_table; u++ )
{
graph( locs[ u ] , map , graphic , pins );
}
}
graphicMap( _location , map , graphic , pins ){
var geocoderRequest = {
address: _location
};
graphic.geocode( geocoderRequest, function(results, status) {
if (status === google.maps.GeocoderStatus.OK){
var marker = new google.maps.Marker({
map:map,
position : results[0].geometry.location,
icon:"images/marker.png",
animation:google.maps.Animation.DROP
});
pins.push( marker );
marker.addListener('click', function() {
for (var i = 0; i < pins.length; i++) {
pins[i].setAnimation(null);
}
if( this.getAnimation() !== null) {
this.setAnimation(null);
} else {
this.setAnimation(google.maps.Animation.BOUNCE);
}
});
console.log( "OK : " + _location );
}else{
console.log( "Error : " + _location );
}
});
}
【问题讨论】:
-
检测到错误时记录服务返回的
status。地理编码器具有配额和速率限制。在前 ~10 个结果之后,您需要遵守速率限制。如果您搜索如何处理 status="OVER_QUERY_LIMIT`,会有很多重复的问题。
标签: javascript google-maps geocoding