On one page multiple entities are displayed. For each entity there is a google map. This is how I deal with displaying a map for only one entity:
var map;
var geocoder;
$(document).ready(function(){
google.maps.event.addDomListener(window, 'load', initialize);
});
function initialize() {
geocoder = new google.maps.Geocoder();
var mapOptions = {
zoom: 16,
center: new google.maps.LatLng(50.317408,11.12915),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('map_canvas'),
mapOptions);
codeAddress($('#entityID span#address').text());
}
function codeAddress(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
});
} else {
codeAddress('germany');
}
});
}
Now I want to show multiple maps, each with a different location. How would that look like? Any ideas? The algorithm should be able to deal with a dynamic amount of entities.
Create an array of maps, something like this: