Маркер карт Google не показывает JavaScript - PullRequest
0 голосов
/ 26 июня 2019

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

var google;

function init() {

var myLatlng = new google.maps.LatLng(40.69847032728747, -73.9514422416687);

var mapOptions = {
    // How zoomed in you want the map to start at (always required)
    zoom: 7,

    // The latitude and longitude to center the map (always required)
    center: myLatlng,

    // How you would like to style the map. 
    scrollwheel: false,
    styles: [
        {
            "featureType": "administrative.country",
            "elementType": "geometry",
            "stylers": [
                {
                    "visibility": "simplified"
                },
                {
                    "hue": "#ff0000"
                }
            ]
        }
    ]
};

Я использую div с id = "map", показанным ниже

var mapElement = document.getElementById('map');

var map = new google.maps.Map(mapElement, mapOptions);

var addresses = ['New York'];

for (var x = 0; x < addresses.length; x++) {
    $.getJSON('http://maps.googleapis.com/maps/api/geocode/json?address='+addresses[x]+'&sensor=false', null, function (data) {
        var p = data.results[0].geometry.location
        var latlng = new google.maps.LatLng(p.lat, p.lng);
        new google.maps.Marker({
            position: latlng,
            map: map,
            title: 'NY'
        });

    });
}

}
google.maps.event.addDomListener(window, 'load', init);

1 Ответ

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