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'});
}
位置在下面声明为坐标数组。我不断得到一些错误,说" this.map_.getZoom不是一个函数"在文件js?key = MYAPIKEY& libraries = places& callback = initMap
答案 0 :(得分:0)
你的新标记功能出了问题。 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' });
}