Google 地图有时不会返回字符串的地理编码值
我有以下代码: 它主要查看 HTML 列表、地理编码并标记每个项目。它十之八九都能正确执行,但有时我会收到我在控制台中设置的显示错误。
我想不出什么。任何想法都非常感激。
$(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>
I have the following code:
It basically looks into a HTML list and geocodes and marks each item. it does it correctly 8 out of ten but sometimes I get an error I set for show in the console.
I can't think of anything. Any thoughts is much appreciated.
$(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());
});
});
which looks into this 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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许是地理编码器查询限制,因为您经常要求 api?
这只是一个猜测。我不止一次遇到这个问题。
Maybe its the geocoders query limit, because you're asking the api to frequently?
Its just a guess. I ran into this problem more than once.