【问题标题】:Google maps api spits errors for markers and markerclustersGoogle maps api 为标记和标记簇吐出错误
【发布时间】:2018-07-15 23:44:12
【问题描述】:
window.initMap=function() {
var options = {
  zoom: 3,
  center: {lat: -28.024, lng: 140.887}
}
var ourmap = new google.maps.Map(document.getElementById('map'),options);

// Add some markers to the map.
// Note: The code uses the JavaScript Array.prototype.map() method to
// create an array of markers based on a given "locations" array.
// The map() method here has nothing to do with the Google Maps API.
var markers = new google.maps.Marker({
    setMap: ourmap,
    position: locations
});

// Add a marker clusterer to manage the markers.
var markerCluster = new MarkerClusterer(map, markers,
    {imagePath: 'https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/m'});
}

locations 在下面声明为一个坐标数组。我在文件 js?key=MYAPIKEY&libraries=places&callback=initMap

中不断收到大量错误,上面写着“this.map_.getZoom 不是函数”

【问题讨论】:

标签: javascript google-maps


【解决方案1】:

您的新标记功能有问题。 setMap 是什么?

尝试编写以下内容,我对其进行了测试,它对我来说没有错误。

        function initMap() {

        var options = {
            zoom: 3,
            center: { lat: -28.024, lng: 140.887 }
        }

        var map = new google.maps.Map(document.getElementById('map'), options);

        // Add some markers to the map.
        // Note: The code uses the JavaScript Array.prototype.map() method to
        // create an array of markers based on a given "locations" array.
        // The map() method here has nothing to do with the Google Maps API.
        var markers = locations.map(function (location, i) {
            return new google.maps.Marker({
                position: location,
                map: map
            });
        });

        // Add a marker clusterer to manage the markers.
        var markerCluster = new MarkerClusterer(map, markers,
            { imagePath: 'https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/m' });
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-10-30
    • 1970-01-01
    • 2012-11-16
    • 2019-10-03
    • 1970-01-01
    • 1970-01-01
    • 2016-07-15
    相关资源
    最近更新 更多