I'm currently trying to make a multiple marker google map on my webpage but trying to get the locations of each marker from the postcode. I have found code for the markers and code for the postcode geocode but I cant seem to find a way to stick them together.
The multiple marker code I have :
<script type="text/javascript">
var locations = [
['Chester', 53.183497, -2.890605, 3, 'https://www.google.co.uk'],
['Manchester', 53.474103, -2.243593, 2, 'https://www.google.co.uk'],
['Liverpool', 53.421206, -2.945146, 1, 'https://www.google.co.uk/']
];
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 9,
center: new google.maps.LatLng(53.381021, -2.608138),
mapTypeId: google.maps.MapTypeId.TERRAIN,
});
var infowindow = new google.maps.InfoWindow();
var marker, i;
for (i = 0; i < locations.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1], locations[i][2]),
url: locations[i][4],
map: map
});
google.maps.event.addListener(marker, 'dblclick', function() {
window.location.href = this.url;
});
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infowindow.setContent(locations[i][0]);
infowindow.open(map, marker);
}
})(marker, i));
}
</script>
postcode geocode code I have :
<html>
<head>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript"></script>
</head>
<body onload="initialize()">
<div align="center" style="height: 30px; width: 530px">
<input id="address" type="textbox">
<input type="button" value="Geocode" onclick="codeAddress()">
</div>
<div id="map" style="height:200px; width: 530px"></div>
</body>
</html>
<script>
var geocoder;
var map;
function initialize()
{
geocoder = new google.maps.Geocoder();
map = new google.maps.Map(document.getElementById("map"),
{
zoom: 8,
center: new google.maps.LatLng(22.7964,79.5410),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
}
function codeAddress()
{
var address = document.getElementById("address").value;
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);
}
});
}
</script>