function initMap(){ var latlng = []; var marker = []; var infoWindow = []; var geocoder = new google.maps.Geocoder(); var townmap = new google.maps.Map(document.getElementById('bihoro_town_map'), { center: {lat: $let, lng: $lng}, zoom: $zoom, }); setMakerInfo(aftergeo); function setMakerInfo(callback){ var cRef = markerData.length; for (var i = 0; i < markerData.length; i++) { (function (i) { geocoder.geocode({'address': markerData[i]['address']}, function(results, status) { if (status === google.maps.GeocoderStatus.OK) { marker[i] = new google.maps.Marker({ position: results[0].geometry.location, map: townmap, }); infoWindow[i] = new google.maps.InfoWindow({ content: '
' + markerData[i]['name'] + '
', }); google.maps.event.addListener(marker[i], 'mouseover',function(){ infoWindow[i].open(townmap, marker[i]); }); google.maps.event.addListener(marker[i], 'mouseout',function(){ infoWindow[i].close(townmap, marker[i]); }); google.maps.event.addListener(marker[i], 'click',function(){ location.href = markerData[i]['link']; }); if(markerData.length == 1){ townmap.setCenter(results[0].geometry.location); } } else { console.log('false'); } if (--cRef <= 0) { callback(); } } ); }) (i); } } function aftergeo(){ } };