如何在点击时打开标记信息窗口,而不是在页面加载时默认打开?
www.driftcoffeehouse.com
<script type="text/javascript" src="http://maps.google.com/maps/api/js?v=3.1&sensor=false"></script>
<script type="text/javascript">
//<![CDATA[
var map;
var geocoder;
initialize();
function initialize() {
geocoder = new google.maps.Geocoder();
geocoder.geocode({
'address': '<?php echo esc_js(get_option('mycuisine_address')); ?>',
'partialmatch': true}, geocodeResult);
}
function geocodeResult(results, status) {
if (status == 'OK' && results.length > 0) {
var latlng = new google.maps.LatLng(results[0].geometry.location.b,results[0].geometry.location.c);
var myOptions = {
zoom: 13,
center: results[0].geometry.location,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("gmaps-container"), myOptions);
var marker = new google.maps.Marker({
position: results[0].geometry.location,
map: map
});
var contentString = '<div id="et-gmaps-content">'+
'<div id="bodyContent">'+
'<p><a target="_blank" href="http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q='+escape(results[0].formatted_address)+'&ie=UTF8&view=map">'+results[0].formatted_address+'</a>'+
'</p>'+
'</div>'+
'</div>';
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map,marker);
})
var infowindow = new google.maps.InfoWindow({
content: contentString,
maxWidth: 100
})
google.maps.event.trigger(marker, "click");
} else {
//alert("Geocode was not successful for the following reason: " + status);
}
}
//]]>
</script>
答案 0 :(得分:0)
创建标记和infowindow后删除google.maps.event.trigger(marker, "click");
,它应该在页面加载时停止打开infowindow。