以下のサンプルスクリプトにおいて、店舗の数を自動取得した上で、
for等の繰り返しを使って「●●」に1~Nの数値を代入したいと考えています。
記述方法について、アドバイスをいただければ幸いです。
// N個の店舗を任意に記述 var shop1 = new google.maps.Marker({ position: new google.maps.LatLng(座標), map: map, icon: 'images/icon1.png', title: '場所1' }); var shop2 = new google.maps.Marker({ position: new google.maps.LatLng(座標), map: map, icon: 'images/icon2.png', title: '場所2' }); // 店舗情報を元に「shop●●」を自動出力 var contentString = shop●●.title; var infowindow●● = new google.maps.InfoWindow({ content: contentString }); google.maps.event.addListener(shop●●, 'click', function() { infowindow●●.open(map,shop●●); });
[参考]
イメージとしては、以下と同等の機能が満たせれば、という意図です。
var contentString = shop1.title; var infowindow1 = new google.maps.InfoWindow({ content: contentString }); google.maps.event.addListener(shop1, 'click', function() { infowindow1.open(map,shop1); }); var contentString = shop2.title; var infowindow2 = new google.maps.InfoWindow({ content: contentString }); google.maps.event.addListener(shop2, 'click', function() { infowindow2.open(map,shop2); }); ・ ・ ・ var contentString = shopN.title; var infowindowN = new google.maps.InfoWindow({ content: contentString }); google.maps.event.addListener(shopN, 'click', function() { infowindowN.open(map,shopN); });
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/02/22 05:38
2016/02/22 06:00 編集
2016/02/22 06:47