Google 地图有时不会返回字符串的地理编码值

发布于 2024-09-03 00:48:28 字数 2440 浏览 3 评论 0原文

我有以下代码: 它主要查看 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

九局 2024-09-10 00:48:28

也许是地理编码器查询限制,因为您经常要求 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文