Created
March 19, 2011 19:44
-
-
Save radu-cojocaru/877750 to your computer and use it in GitHub Desktop.
Plot a UK post code on Google Maps
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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