Following code works ok, except that it not zoom to the given points.
If I take the Latlng direct it works, without convert the address to Latlng.
I need to convert a address to latlng because I get the addresses out of a database.
Anyone an idea what is wrong?
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Google Maps Test</title>
<script src="http://maps.google.com/maps/api/js?sensor=false"
type="text/javascript"></script>
</head>
<body>
<div id="map" style="width: 600px; height: 400px;"></div>
<script type="text/javascript">
var arrAddress = new Array();
arrAddress[0] = "kelbergen, Amsterdam";
arrAddress[1] = "Kraailookstraat, Amsterdam";
arrAddress[2] = "krootstraat, Amsterdam";
var optionMap = {
zoom: 16,
MapTypeId: google.maps.MapTypeId.ROADMAP,
};
var map = new google.maps.Map(document.getElementById('map'), optionMap);
var geocoder = new google.maps.Geocoder();
var latlngbounds = new google.maps.LatLngBounds();
for(var i = 0; i < arrAddress.length; i++) {
geocoder.geocode( { 'address': arrAddress[i]}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
latlngbounds.extend(results[0].geometry.location);
}
});
}
map.fitBounds(latlngbounds);
</script>
</body>
</html>