2016-08-05 3 views
-2

誰かがJavaScriptのGoogleマップ情報ウィンドウにクリックイベントを追加する方法を知っていますか? ポップアップ情報ウィンドウからクリックイベントを取得できます。 これは可能ですか?どのようにjavascriptでGoogleマップのinfowindowにクリックイベントを追加することができます

+1

のために動作しますチェックはい、それはあなたが、彼は私あなたの答え – mean

+4

重複質問を編集します情報ウィンドウのレンダリングされているマップコードグーグルpossible.Writeでくださいhttp://stackoverflow.comを/ question/12102598/trigger-event-with-infowindow-or-infobox-on-click-google-map-api-v3 – codeGig

答えて

2
<!DOCTYPE html> 
<html> 
<head> 
<script 
src="http://maps.googleapis.com/maps/api/js"> 
</script> 

<script> 
var myCenter=new google.maps.LatLng(51.508742,-0.120850); 

function initialize() 
{ 
var mapProp = { 
    center:myCenter, 
    zoom:5, 
    mapTypeId:google.maps.MapTypeId.ROADMAP 
    }; 

var map=new google.maps.Map(document.getElementById("googleMap"),mapProp); 

var marker=new google.maps.Marker({ 
    position:myCenter, 
    }); 

marker.setMap(map); 

var infowindow = new google.maps.InfoWindow({ 
    content:"<button onclick='xyz()'>abcd</button>" 
    }); 

google.maps.event.addListener(marker, 'click', function() { 
    infowindow.open(map,marker); 
    }); 
} 

google.maps.event.addDomListener(window, 'load', initialize); 

function xyz(){ 
alert('Hello') 
} 
</script> 
</head> 

<body> 
<div id="googleMap" style="width:500px;height:380px;"></div> 
</body> 
</html> 

これはあなた

+0

ありがとうございます、私は理解しているように、ポップアップウィンドウにボタンを追加し、他の解決策はありません。 – Developer

+0

私はすぐにコードを更新することが可能です – mean

+0

おかげであなたは私の日を保存しました....... :-) –

関連する問題