Google maps иногда не возвращает геокодированное значение для строки - PullRequest
0 голосов
/ 28 мая 2010

У меня есть следующий код: Он в основном просматривает список HTML и геокодов и отмечает каждый элемент.он делает это правильно, 8 из 10, но иногда я получаю сообщение об ошибке, которое я установил для показа в консоли.

Я ничего не могу придумать.Любые мысли очень ценятся.

$(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>

1 Ответ

0 голосов
/ 31 мая 2010

Может быть, это предел запросов геокодеров, потому что вы часто спрашиваете API?
Это просто предположение. Я сталкивался с этой проблемой более одного раза.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...