按照谷歌文档更改标记图标很容易。但是我被卡住了,我不知道单击标记时如何更改图像?
到目前为止我的代码:
<script>
function initialize() {
var latlngPos = new google.maps.LatLng(<?php echo $event_google_map_coordinates; ?>);
var mapOptions = {
zoom: 16,
center: latlngPos,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById('googlemap_event'),
mapOptions);
var marker = new google.maps.Marker({
position: latlngPos,
map: map,
//animation: google.maps.Animation.BOUNCE,
icon: '<?= get_bloginfo("template_url"); ?>/images/marker.png'
});
var infowindow = new google.maps.InfoWindow({
position: latlngPos,
maxWidth: 200,
content: "<h3><?php the_title(); ?></h3><?php if ($event_address_meta) {_e($event_address_meta);} ?>"
});
//open onclick
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map);
});
//open infowindow onload
//infowindow.open(map);
}
function loadScript() {
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'http://maps.googleapis.com/maps/api/js?key=AIzaSyCK3XUMWOH0GIiuj3VeprakKZXoo_nDV08&sensor=false&' +
'callback=initialize';
document.body.appendChild(script);
}
window.onload = loadScript; < /script>
<div id="googlemap_event"></div>