Google Maps JSON代码“标记我的位置不起作用”

时间:2018-11-10 17:02:43

标签: javascript json maps

有人可以告诉我此代码有什么问题吗? 我看不到我在此代码上指定的地址:

(function($){

    $(document).ready(function () {
        var map = new google.maps.Map($('#map_canvas_contactus')[0]);

        var addresses = ["54 Scholars Ct, Northampton, Northamptonshire NN1 1ES, United Kingdom","JMC House Newlands Naas Rd 22 Co, Dublin 15, Dublin ,Ireland"];

        var infowindow = new google.maps.InfoWindow();
        var bounds = new google.maps.LatLngBounds();

        var marker_icon = new google.maps.MarkerImage('images/marker_office.png',
            new google.maps.Size(43, 63), // This marker is 129 pixels wide by 42 pixels tall.
            new google.maps.Point(0,0),// The origin for this image is 0,0.
            new google.maps.Point(21, 63)// The anchor for this image is the base of the flagpole at 18,42.
        );

        var marker_html;

        for (var i = 0; i < addresses.length; i++) {

            marker_html = "Safty Gear ";

            $.getJSON('http://maps.googleapis.com/maps/api/geocode/json?address=' + addresses[i] + '&sensor=false', null, function (data) {

                var p = data.results[0].geometry.location
                var latlng = new google.maps.LatLng(p.lat, p.lng);

                var marker = new google.maps.Marker({
                    position: new google.maps.LatLng(p.lat, p.lng),
                    map: map,
                    icon: marker_icon, // This path is the custom pin to be shown. Remove this line and the proceeding comma to use default pin
                });

                bounds.extend(marker.position);

                google.maps.event.addListener(marker, 'click', (function (marker, x) {
                    return function () {
                        infowindow.setContent(marker_html);
                        infowindow.open(map, marker);
                    }
                })(marker, i));

            });
        }

        map.fitBounds(bounds);

        var listener = google.maps.event.addListener(map, "idle", function () {
            map.setZoom(4);
            google.maps.event.removeListener(listener);
        });
    });        
})(jQuery);

0 个答案:

没有答案