Google Maps API 3のサンプルをいくつかダウンロードしましたが、次のようなコードが表示されます。
(function (i, marker) {
google.maps.event.addListener(marker, 'click', function () {
if (!infowindow) {
infowindow = new google.maps.InfoWindow();
}
infowindow.setContent("Message" + i);
infowindow.open(map, marker);
});
})(i, marker);
誰かがこれが何を意味するのか説明してもらえますか?または、上記のコードをさまざまな方法で書き直すことはできますか?私はJavaScriptに少し慣れていませんが、上記のコードが正確に何をするのかわかりませんか?
これが完全なスクリプトです
関数markicons(){
InitializeMap();
var ltlng = [];
ltlng.push(new google.maps.LatLng(17.22, 78.28));
ltlng.push(new google.maps.LatLng(13.5, 79.2));
ltlng.push(new google.maps.LatLng(15.24, 77.16));
map.setCenter(ltlng[0]);
for (var i = 0; i <= ltlng.length; i++) {
marker = new google.maps.Marker({
map: map,
position: ltlng[i]
});
(function (i, marker) {
google.maps.event.addListener(marker, 'click', function () {
if (!infowindow) {
infowindow = new google.maps.InfoWindow();
}
infowindow.setContent("Message" + i);
infowindow.open(map, marker);
});
})(i, marker);
}
}