Javascript 谷歌地图有时不返回字符串的地理编码值
我有以下代码: 它基本上查看HTML列表和地理编码,并标记每个项目。它十有八九是正确的,但有时我会在控制台中设置一个显示错误 我想不出什么。任何想法都是非常感谢的Javascript 谷歌地图有时不返回字符串的地理编码值,javascript,google-maps,geolocation,Javascript,Google Maps,Geolocation,我有以下代码: 它基本上查看HTML列表和地理编码,并标记每个项目。它十有八九是正确的,但有时我会在控制台中设置一个显示错误 我想不出什么。任何想法都是非常感谢的 $(function () { var map = null; var geocoder = null; function initialize() { if (GBrowserIsCompatible()) { // Specifies that the element with the ID map i
$(function () {
var map = null;
var geocoder = null;
function initialize() {
if (GBrowserIsCompatible()) {
// Specifies that the element with the ID map is the container for the map
map = new GMap2(document.getElementById("map"));
// Sets an initial map positon (which mainly gets ignored after reading the adderesses list)
map.setCenter(new GLatLng(37.4419, -122.1419), 13);
// Instatiates the google Geocoder class
geocoder = new GClientGeocoder();
map.addControl(new GSmallMapControl());
// Sets map zooming controls on the map
map.enableScrollWheelZoom();
// Allows the mouse wheel to control the map while on it
}
}
function showAddress(address, linkHTML) {
if (geocoder) {
geocoder.getLatLng(address,
function (point) {
if (!point) {
console.log('Geocoder did not return a location for ' + address);
}
else {
map.setCenter(point, 8);
var marker = new GMarker(point);
map.addOverlay(marker);
// Assigns the click event to each marker to open its balloon
GEvent.addListener(marker, "click", function () {
marker.openInfoWindowHtml(linkHTML);
});
}
}
);
}
} // end of show address function
initialize();
// This iterates through the text of each address and tells the map
// to show its location on the map. An internal error is thrown if
// the location is not found.
$.each($('.addresses li a'), function () {
var addressAnchor = $(this);
showAddress(addressAnchor.text(), $(this).parent().html());
});
});
查看此HTML:
<ul class="addresses">
<li><a href="#">Central London</a></li>
<li><a href="#">London WC1</a></li>
<li><a href="#">London Shoreditch</a></li>
<li><a href="#">London EC1</a></li>
<li><a href="#">London EC2</a></li>
<li><a href="#">London EC3</a></li>
<li><a href="#">London EC4</a></li>
</ul>
这可能是地理编码器的查询限制,因为您经常要求api进行查询?这只是猜测。我不止一次遇到这个问题。对所有的基本评论表示抱歉。客户需要知道每一行的功能。你是说同一地址的每一行都会间歇性地出现故障,还是说通常只有2/10出现故障?完全是随机故障。有时是因为以前找到过地址,有时是因为所有地址。然后我刷新,它又可以正常工作了。谢谢你给我虚拟化的答案。这很可能就是你的建议。虽然我正在测试一个来自美国认可国家的应用程序,但如果这与此有关,该服务可能根本不起作用,而不是有时失败。我想这就是我必须建议我的客户获得谷歌地图商业许可证的情况。