Маркеры Googlemaps не загружаются - PullRequest
1 голос
/ 21 февраля 2012

Я новичок в этом сайте, плохо знаком с картами Google и довольно плохо знаком с javascript, поэтому, пожалуйста, будьте немного терпеливы.

Мне было поручено добавить несколько интерфейсов карт Google на сайт, который я администрирую, поэтому я следовал инструкциям по Google, и я дошел до отображения карты, геокодирования адресных строк и установки маркеров. Вот в чем проблема, первый геокодированный указатель всегда появляется, но остальные появляются только периодически (обычно при первой загрузке или после нескольких перезагрузок). Firebug сообщает о следующей ошибке:

"Недопустимое значение для свойства: (53.3800136, -1.475428500000021) в строке 28 main.js"

Я думаю, что я обнаружил функцию-нарушитель, сценарий, кажется, периодически останавливается в этой точке, останавливая загрузку других маркеров. Я перепробовал все подходящие решения, которые смог найти, и теперь ничего не сработало. Я в тупике, может кто-нибудь помочь? вот мой код для справки:

     function load_map() {
            var startLatLng = new google.maps.LatLng(52.485809,-1.888783);
            // create a new Google latLang marker object with co-ords for
            // start location

            // create a JASON object to store map configuration
            var config = {
                zoom: 5,
                center: startLatLng,
                mapTypeId: google.maps.MapTypeId.ROADMAP
            };


            map = new google.maps.Map(document.getElementById("map"), config);
            // initialise the map passing the display divs id and the config
            // object

            var startMarker = new google.maps.Marker({
                position: startLatLng,
                map: map
            })

            // create a new marker object for start location
            startMarker.setMap(map);
            // Add the marker to the map

            geocodeAddress("ARM Ltd Rockingham Court 152 Rockingham Street Sheffield Great Britain");
            geocodeAddress("Centrum House 36 Station Road Egham Surrey");
            geocodeAddress("Pipers Way Swindon United Kingdom");
            // call the geocoding function to add markers to the map hard coded right now for testing 
           // but to be pulled from a DB in future
        }

        /*
         * This function loads a marker overlay on to the location provided
         * and calls the addInfoWindow function to add an info window to it
         *
         * @ param a google location object representing the location at which
         * the marker is to be placed
         * @ param a String variable representing the information to be attached
         * to the window.
         */

        function loadMarker(location,windowText) {
            var tempMarker = new google.maps.Marker({
                position: location,
                map: map
            });

            addInfoWindow(windowText,tempMarker);
            // add an information window anchored on the marker

            tempMarker.setMap(location); // seems to work ok up to this point.
            // add the marker to the map at this location

        }

        /*
         * A function to geocode the string type address passed into usable
         * lat lng type co-ords
         * @ param a String representing the address to be geocoded
         */

        function geocodeAddress (address) {
            var geocoder = new google.maps.Geocoder();
            geocoder.geocode( {'address': address}, function(results, status) {
                if (status == google.maps.GeocoderStatus.OK) {
                    loadMarker(results[0].geometry.location,"Info here");
                } else {
                    alert("Geocode was not successful for the following reason: " + status);
                }
            });
        }

        /*
         * This function adds an info window to each marker and allows it
         * to be activated on click.
         * @Param
         */

        function addInfoWindow (infoText,marker) {
            var contentString = infoText;
            var tempInfoWindow = new google.maps.InfoWindow({
                content: contentString
            });
            google.maps.event.addListener(marker, 'click', function() {
                tempInfoWindow.open(map,marker);
            });
        }
        // initialise all the page components by calling there load functions

        // called using a standard body onload to intilise the map
        function init () {
            load_map();
        }   

1 Ответ

0 голосов
/ 22 февраля 2012

В строке 53 неправильно указаны location вместо map

Измените свой код с:

tempMarker.setMap(location);

до

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