0
如何讓標記infowindow在點擊時打開,而不是在頁面加載時默認打開?打開Infowindow點擊谷歌地圖
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>
請問您可以格式化您的代碼,使其可讀(在開始時刪除所有無關的空白區域併合理地縮進代碼)? – geocodezip
很抱歉,第一次海報,你可以看到:/ – Owen