I've tried loads of combinations and read through loads of articles on Stackoverflow but can't seem to get this to work.. Should be real easy but proving to be a right pain in the backside so just wondering if anyone can help..
simply trying to add some markers to a google map (& eventually directions) I have below code but all I get is blank screen.. If I strip out the markers code I do get the bare map so it is working in the page at least... can anyone help..?
<script type="text/javascript">
//<![CDATA[
var geocoder;
var map;
function initialize() {
geocoder = new google.maps.Geocoder();
var mapOptions = {
zoom: 7
}
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
codeAddress();
}
function codeAddress() {
var address = ['SO21 3NE','Horsham'];
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 {
alert('Geocode was not successful for the following reason: ' + status);
}
});
}
google.maps.event.addDomListener(window, 'load', initialize);//]]>
</script>
this fixed it...
var locations = ['SO21 3NE','Horsham','RG45 7EG'];
var infowindow = new google.maps.InfoWindow();
var marker, i;
var geocoder = new google.maps.Geocoder();
var mapOptions = {
zoom: 7
}
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
for (i = 0; i < locations.length; i++) {
geocoder.geocode( { 'address': locations[i]}, function(results, status) {
//alert(status);
if (status == google.maps.GeocoderStatus.OK) {
//alert(results[0].geometry.location);
map.setCenter(results[0].geometry.location);
marker = new google.maps.Marker({
position: results[0].geometry.location,
map: map
});
google.maps.event.addListener(marker, 'mouseover', function() { infowindow.open(map, marker);});
google.maps.event.addListener(marker, 'mouseout', function() { infowindow.close();});
}
else
{
alert("some problem in geocode" + status);
}
});
}
google.maps.event.addDomListener(window, 'load', initialize);