var map = null; var geocoder = null; var infowindow = null; var locationArray = ["51.563276, 5.043143" ]; function googleload() { var myOptions = { zoom: 16, center: new google.maps.LatLng(52.559,5.559), disableDefaultUI: true, panControl: true, zoomControl: true, zoomControlOptions: { style: google.maps.ZoomControlStyle.SMALL }, mapTypeControl: true, mapTypeId: google.maps.MapTypeId.ROADMAP, scaleControl: true, streetViewControl: false, overviewMapControl: false, disableDoubleClickZoom: false } map = new google.maps.Map(document.getElementById("map"), myOptions); geocoder = new google.maps.Geocoder(); } function showAddress(address) { geocoder.geocode( { 'address': address}, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { map.setCenter(results[0].geometry.location); var marker = new google.maps.Marker({ map: map, position: results[0].geometry.location, title: results[0].address_components[0].long_name }); google.maps.event.addListener(marker, 'click', function() { if (infowindow) { infowindow.close(); } infowindow = new google.maps.InfoWindow({content:marker.getTitle()}); infowindow.open(map,marker); }); } else { //alert("Geocode was not successful for the following reason: " + status); } }); } function showAddresses(addresses) { var bounds = new google.maps.LatLngBounds(); for(var i=0; i < addresses.length; i++) { if (geocoder) { geocoder.geocode( { 'address': addresses[i]}, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { map.setCenter(results[0].geometry.location); var marker = new google.maps.Marker({ map: map, position: results[0].geometry.location, title: results[0].address_components[0].long_name }); google.maps.event.addListener(marker, 'click', function() { if (infowindow) { infowindow.close(); } infowindow = new google.maps.InfoWindow({content:marker.getTitle()}); infowindow.open(map,marker); }); bounds.extend(marker.getPosition()); map.fitBounds(bounds); } else { //alert("Geocode was not successful for the following reason: " + status); } }); } } } function load(){ googleload(); if (locationArray.length > 1) { showAddresses(locationArray); } else { showAddress(locationArray[0]); } } window.onload = load;