html,正文{高度:100%;边距:0; 填充:0; } #map {高度:100%;} //创建一个map变量var map; var markers = []; //用于在地图div函数initMap(){map = new google.maps.Map(document.getElementById('map'),{center:{lat:40.74135,lng:-73.99802},缩放:)中初始化地图的函数: 14});
{title: 'Markerul', location: {lat: 40,7713024, lng: -73.9632393}}
];
var largeInfowindow = new google.maps.InfoWindow();
for(var i = 0; i<locations.length; i++){
var positions = locations[i].location;
var title = locations[i].title;
var marker = new google.maps.Marker({
map: map,
position: position,
title: title,
animation: google.maps.Animation.DROP,
id: i
});
markers.push(marker);
// onclick
marker.addListener('click', function (){
populateInfoWindow(this, largeInfowindow);
});
}
function populateInfoWindow(marker, infowindow){
// verifica daca fereastra de info nu este deja deschisa
if(infowindow.marker !=marker){
infowindow.marker = marker;
infowindow.setContent('<div>' + marker.title + '</div>');
infowindow.open(map, marker);
infowindow.addListener('closeclick', function(){
infowindow.setMarker(null);
});
}
}
var largeInfowindow = new google.InfoWindow();
var bounds = new google.maps.LatLngBounds();
// crearea unei arii de markere
for (var i = 0; i < locations.length; i++){
// ia pozitia
var position = locations[i].location;
var title = locations[i].title;
//crearea unui marker per locatie si punerea lui in aria de markere
var marker = new google.maps.Marker({
map: map,
position: position,
title: title,
animation: google.maps.Animation.DROP,
id: i
});
//push the marker to our array of markers
markers.push(marker);
//extinderea ariei pt markere
bounds.extend(marker.position);
//onclick
marker.addListener('click', function (){
populateInfoWindow(this, largeInfowindow);
});
}
map.fitBounds(bounds);
}
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。