【发布时间】:2017-08-01 19:13:30
【问题描述】:
我一直在玩 Google Maps javascript,希望有人可以帮助我让我的标记弹跳。我有一组标记,我希望链接、div 或标题(h1)的鼠标悬停可以使特定标记反弹。
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 11,
center: {
lat: -37.800426,
lng: 145.038494
}
});
setMarkers(map);
}
// Data for the markers consisting of a name, a LatLng and a zIndex for the
// order in which these markers should display on top of each other.
var stores = [
['A', -37.771624, 144.888128, 1],
['B', 37.843956, -144.994875, 2],
['C', -37.818086, 144.995699, 3],
['D', 37.812697, -145.229200, 4],
];
function setMarkers(map) {
// Adds markers to the map.
for (var i = 0; i < stores.length; ++i) {
var store = stores[i];
var marker = new google.maps.Marker({
position: {
lat: store[1],
lng: store[2]
},
map: map,
animation: google.maps.Animation.DROP,
title: store[0],
zIndex: store[3],
});
attachStoreTitle(marker);
}
}
// Attaches an info window to a marker with the provided message. When the
// marker is clicked, the info window will open with the secret message.
function attachStoreTitle(marker, storeName) {
var infowindow = new google.maps.InfoWindow({
content: marker.title
});
marker.addListener('click',
function() {
infowindow.open(marker.get('map'), marker);
});
}
考虑到所有数据都在一个数组中,我遇到的另一个主要问题是调用正确的标记。
【问题讨论】:
标签: javascript google-maps google-maps-api-3 maps