【发布时间】:2015-04-17 14:01:03
【问题描述】:
我正在使用以下脚本来显示一张带有两个标记的地图。如果我将鼠标悬停在标记上,则会出现一个带有该位置的弹出工具提示。我的问题是如何让信息默认显示而不是鼠标悬停?
google.maps.event.addDomListener(window, 'load', init);
var map;
function init() {
var mapOptions = {
center: new google.maps.LatLng(37.1370345, 74.3872165),
zoom: 3,
zoomControl: true,
zoomControlOptions: {
style: google.maps.ZoomControlStyle.SMALL,
},
disableDoubleClickZoom: false,
mapTypeControl: false,
scaleControl: true,
scrollwheel: false,
streetViewControl: true,
draggable: true,
overviewMapControl: false,
mapTypeId: google.maps.MapTypeId.ROADMAP,
styles: [{
"featureType": "administrative",
"elementType": "labels.text.fill",
"stylers": [{
"color": "#444444"
}]
}, {
"featureType": "landscape",
"elementType": "all",
"stylers": [{
"color": "#111111"
}, {
"lightness": 50
}]
}, {
"featureType": "poi",
"elementType": "all",
"stylers": [{
"visibility": "off"
}]
}, {
"featureType": "road",
"elementType": "all",
"stylers": [{
"saturation": -100
}, {
"lightness": 45
}]
}, {
"featureType": "road.highway",
"elementType": "all",
"stylers": [{
"visibility": "on"
}]
}, {
"featureType": "road.arterial",
"elementType": "labels.icon",
"stylers": [{
"visibility": "off"
}]
}, {
"featureType": "transit",
"elementType": "all",
"stylers": [{
"visibility": "off"
}]
}, {
"featureType": "water",
"elementType": "all",
"stylers": [{
"color": "#ffffff"
}, {
"visibility": "on"
}]
}],
}
var mapElement = document.getElementById('map1');
var map = new google.maps.Map(mapElement, mapOptions);
var locations = [
['Country 1', 39.690642467918366, 39.07426848448813],
['Country 2', 39.682790, 19.764394]
];
var infowindow = new google.maps.InfoWindow({
content: "Loading..."
});
var myIcon = new google.maps.MarkerImage("http://i.imgur.com/jRfjvrz.png", null, null, null, new google.maps.Size(46, 46));
for (i = 0; i < locations.length; i++) {
marker = new google.maps.Marker({
content: locations[i][0],
icon: myIcon,
position: new google.maps.LatLng(locations[i][1], locations[i][2]),
animation: google.maps.Animation.DROP,
optimized: false,
map: map
});
google.maps.event.addListener(marker, 'mouseover', function () {
infowindow.setContent(this.content);
infowindow.open(map, this);
});
}
}
【问题讨论】:
-
将您的弹出窗口存储在一个数组/对象中,然后简单地调用
infowindow.open每个
标签: javascript jquery html css google-maps