-
-
Save tatsuro-ueda/1760884 to your computer and use it in GitHub Desktop.
Google Mapで複数のマーカーの情報ウィンドウを切り替える
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var op={ | |
zoom:15, | |
center:new google.maps.LatLng(35.7078118,139.5773074), | |
mapTypeId:google.maps.MapTypeId.ROADMAP | |
}; | |
var map=new google.maps.Map(document.getElementById("map_canvas"),op); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var obj={ | |
position: new google.maps.LatLng(35.708104, 139.577644), | |
map:map | |
}; | |
marker[0]=new google.maps.Marker(obj); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
info[0] = new google.maps.InfoWindow({ content: '<p>トヨタレンタリース東京 吉祥寺</p>' }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
google.maps.event.addListener(marker[0], 'click', function () { | |
if (info[1]) info[1].close(); | |
info[0].open(map, marker[0]); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function initialize() { | |
var marker = new Array; | |
var info = new Array; | |
// Mapクラスを生成 | |
// MapOptionsオブジェクトの設定して、Mapクラスの引数に指定します。 | |
var op={ | |
zoom:15, | |
center:new google.maps.LatLng(35.7078118,139.5773074), | |
mapTypeId:google.maps.MapTypeId.ROADMAP | |
}; | |
var map=new google.maps.Map(document.getElementById("map_canvas"),op); | |
// Markerクラスを生成 | |
// MarkerOptionsオブジェクトの設定して、Markerクラスの引数に指定します。 | |
var obj={ | |
position: new google.maps.LatLng(35.708104, 139.577644), | |
map:map | |
}; | |
marker[0]=new google.maps.Marker(obj); | |
// Markerに情報ウィンドウを表示させる | |
// InfoWindowOptionsオブジェクトを設定して、InfoWindowクラスを生成します。 | |
// 生成したInfoWindowを使って、自動的にMarkerから情報ウィンドウを表示させます。 | |
// content には、HTMLのソースが指定できるので、画像やリンクを貼ったりもできます。 | |
info[0] = new google.maps.InfoWindow({ content: '<p>トヨタレンタリース東京 吉祥寺</p>' }); | |
//info[0].open(map,marker); | |
// Markerがクリックされたときに、情報ウィンドウを表示させる | |
// イベントリスナーを使って、Markerがクリックされたときに情報ウィンドウを表示させます。 | |
// もう一つの情報ウィンドウが開いていたら閉じます。 | |
google.maps.event.addListener(marker[0], 'click', function () { | |
if (info[1]) info[1].close(); | |
info[0].open(map, marker[0]); | |
}); | |
var obj = { | |
position: new google.maps.LatLng(35.707729, 139.577865), | |
map: map | |
}; | |
marker[1] = new google.maps.Marker(obj); | |
info[1] = new google.maps.InfoWindow({ content: '<p>武蔵野警察署八幡西宮交番</p>' }); | |
google.maps.event.addListener(marker[1], 'click', function () { | |
if (info[0]) info[0].close(); | |
info[1].open(map, marker[1]); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment