Reputation: 1475
I need a simple way to display a map, using the API v3, which is generated by using a UK postcode. No search field needed, just a static postcode per map.
Does anyone have a good way to do this?
Upvotes: 1
Views: 3228
Reputation: 6232
I had a similar problem and posted the code here:
how to use the google maps api with greasemonkey to read a table of addresses and trace the route?
Take a look and check if it helps you.
The code below uses the USA zip code to return the state, but i believe you can modify it to your needs.
var geocoder = new google.maps.Geocoder();
function getState(zipcode) {
geocoder.geocode( { 'address': zipcode}, function (result, status) {
var state = "N/A";
for (var component in result[0]['address_components']) {
for (var i in result[0]['address_components'][component]['types']) {
if (result[0]['address_components'][component]['types'][i] == "administrative_area_level_1") {
state = result[0]['address_components'][component]['short_name'];
// do stuff with the state here!
document.getElementById('state').innerHTML = state;
return;
}
}
}
});
}
--- EDITED [28/10/2011] ---
ok. very simple example, no code needed.
click here.
all you have to do is change the postcode SW1A where it says center=SW1A,UK
.
cant get any simpler than that :)
Upvotes: 1