0
なぜ私はマーカーの情報ウィンドウの内容に自分のアドレスを取得できないのですか?私のループでは、geocoderstatusの前に私は私のアドレス情報を持っていますが、geocoderstatus.okの後に私は定義されていないか、私の配列の最後のアドレスしか持っていません。Javascript google maps foreach infowindows
function geocodeAddress(resultsMap) {
// var address = document.getElementById('address').value;
var address = ["Brussel","Oostende","Brugge","Gent","Luik"];
for(var i = 0; i < address.length;i++)
{
//new
var geocoder = new google.maps.Geocoder();
var geooptions = {
address: address[i]
}
geocoder.geocode(geooptions, function (results, status) {
if (status === google.maps.GeocoderStatus.OK) {
// resultsMap.setCenter(results[0].geometry.location)
addMarker(resultsMap,address[i], results[0].geometry.location);
} else {
alert('Geocode was not successful for the following reason: ' + status);
}
});
}
}
function addMarker(map,item,location) {
console.log(item);
var marker= new google.maps.Marker({
map: map,
position: location, //results[0].geometry.location,
title: item
});
var infowindow = new google.maps.InfoWindow({
content: item
});
marker.addListener('click', function() {
infowindow.open(map, marker);
});
}