Skip to content

Instantly share code, notes, and snippets.

@frontweb
Created March 19, 2011 19:44
Show Gist options
  • Save frontweb/877750 to your computer and use it in GitHub Desktop.
Save frontweb/877750 to your computer and use it in GitHub Desktop.
Plot a UK post code on Google Maps
<html>
<head>
<title>UK Post Code</title>
<style type="text/css">
#map_canvas { width:300px; height:200px; }
</style>
<script type="text/javascript">
function initialize() {
var geocoder = new google.maps.Geocoder();
var myLatlng = new google.maps.LatLng(-34.397, 150.644);
var myOptions = {
zoom: 14,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
geocoder.geocode({ 'address': "W2 6LE, UK"}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var location = results[0].geometry.location;
map.setCenter(location);
var marker = new google.maps.Marker({map: map, position: location, name: "W2 6LE"});
markers.push(marker);
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
function loadScript() {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "http://maps.google.com/maps/api/js?sensor=false&callback=initialize";
document.body.appendChild(script);
}
window.onload = loadScript;
</script>
</head>
<body>
<div id="map_canvas"></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment