Geocoding UK Postcodes with Google Map API
Notice: As a few people have pointed out, this announcement from Google means Geocoding is now built in. Yet as more people have pointed out - it kinda sucks accuracy wise (think over a mile off on some postcodes!), whereas my method continues to be accurate.
Google Maps API provides a geocoding feature, for finding the latitude and longitude of places or addresses; but it does not work for UK postcodes. This is thanks to Royal Mail who have a copyright on the data, and are very restrictive with their (expensive) licenses for it.
There are various solutions out there for using 3rd party services and importing the data to be used with Google Maps, or for using community built databases for the info. However, I’ve had a few people ask me about doing it just though Google.
It is possible — Google AJAX Search API does provide geocoding for UK postcodes. We need to use the two APIs in harmony to achieve our result.
So here it is.
Step by step
I’ll assume you already know how to use Google Maps API, and you came here just looking how to add geocoding for the UK.
Step 1.
Grab a two API keys, if you already have your Google Maps API key, just grab an AJAX search key. You can get them here:
http://www.google.com/apis/maps/signup.html
http://code.google.com/apis/ajaxsearch/signup.html
Step 2.
Google will give you a sample page, you need to stick your two API keys at the top of the page, followed by a reference to your Javascript file:
<script src="http://maps.google.com/maps?file=api&v=2&key=*KEY*"
type="text/javascript"></script>
<script src="http://www.google.com/uds/api?file=uds.js&v=1.0&key=*KEY*"
type="text/javascript"></script>
<script src="gmap.js" type="text/javascript"></script>
Ensure the reference to your Javascript file comes after the two API keys.
Step 3.
In addition to the Google Maps API stuff, you need to stick a reference to Google local search at the top of your Javascript file:
var localSearch = new GlocalSearch();
You can grab my Javascript file right here, but remember you’ll need to change the API keys.
Step 4.
The key to this Geocoder is only a single function:
function usePointFromPostcode(postcode, callbackFunction) {
localSearch.setSearchCompleteCallback(null,
function() {
if (localSearch.results[0]) {
var resultLat = localSearch.results[0].lat;
var resultLng = localSearch.results[0].lng;
var point = new GLatLng(resultLat,resultLng);
callbackFunction(point);
}else{
alert("Postcode not found!");
}
});
localSearch.execute(postcode + ", UK");
}
It takes 2 arguments; postcode is the postcode you want to look for, and callbackFunction is the function you wish to run on the results.
Why is it necessary to do it this way? It is the way AJAX, and thus Google AJAX Search API, works - the request is sent, and a callback function is designated to handle the results returned, when they are ready.
In our case, the callback function can do whatever you want with the results, which will come in the format of a GLatLng (often just called a point); I’ve supplied 2 sample functions, placeMarkerAtPoint and setCenterToPoint which do pretty much what they sound like they do.
Step 5.
Putting aside accessibility and graceful degradation for the sake of simplicity in this tutorial, the last step we need is just to add some hooks into our Javascript:
<input type="text" id="postcode" size="10" />
<input type="submit" value="Place Marker" onclick="javascript:
usePointFromPostcode(document.getElementById('postcode').value, placeMarkerAtPoint)" />
We have a field for inputting a postcode, and I’ve added a button for placing a marker there. Where I have placeMarkerAtPoint you can put a reference to your own function, or you can even add a function right in there, like this:
<input type="submit" value="Do whatever" onclick="javascript:
usePointFromPostcode(document.getElementById('postcode').value,
function (point) {
alert('Latitude: ' + point.lat() + '\nLongitude: ' + point.lng());
})" />
Demo
If you are coming in from an RSS reader, either visit this blog post on the site, or see the demo page.
Postcode:
Conclusion
Until Royal Mail sort get their act together, and relax the licensing agreement, hopefully this will help people who want a ‘pure’ Google solution and hadn’t come across this option. Please use the comments section to let me know if you are using this, or if you have any improvements or suggestions.
Technorati Tags: postcode, google maps, api, Web 2.0, Web-Services





Dan said,
March 5, 2007 @ 4:29 pm
Brilliant, so simple been looking to the answer for this one for a while.
Lee said,
March 8, 2007 @ 7:57 am
Well, Well, Well Mr Anthony… You decided to actually do some work sitting in the bloody caribean!! .. hehehhe
Nice post bud… I’ll have a good read later today when I am more awake, hope your doing well over there
Eliphas said,
March 12, 2007 @ 5:43 pm
Nice tutorial, but now I would like to go further and i am stuck. how can i query the geocoder from a from and retrieve the lon and lat from the javascript and inseet them into a database can you provide me some tips .
thanks a lot.
Tom said,
March 12, 2007 @ 5:58 pm
Hi Eliphas,
Previously, in the terms and conditions there was a clause that you couldn’t store geocode data back into a database; however it doesn’t seem to be there anymore.
Because the lat/long are retrieved via Javascript, you will need to use an AJAX request to send this information back to your server. You would probably create a server side script (PHP, ASP or similar), and then POST this data back to your server via an AJAX connection.
Your server side script would then receive the data and write it to your database.
If I get time, I will write a quick tutorial on caching geocoding results this week. That should help you if you need further assistance.
mark said,
March 14, 2007 @ 1:38 pm
Hi,
Thanks for your tutorial, how would you get the following page to work and open the map directly on the passed postcode?
http://www.pets4homes.co.uk/pets4homes/home.nsf/TestMap?openForm&PostCode=bb24jh
I tried adding the following line to the onload event but it doesnt work :
usePointFromPostcode(document.getElementById(’postcode’).value, setCenterToPoint)
Thanks
Mark
Tom said,
March 14, 2007 @ 2:07 pm
Hi Mark,
getElementById()will only retrieve elements in the DOM tree; usually meaning elements you can see rendered on the page.What you need to do it to get a query string parameter from the URL; it isn’t as scary as it sounds, and there is a good article (complete with function) on it here:
http://www.netlobo.com/url_query_string_javascript.html
Using the function from the article, you’d then need to do something like:
I’ve not tested this code - but it should be something like that.
Good luck!!
Ryan Cullen said,
March 14, 2007 @ 4:11 pm
THANK YOU.
I’ve been looking for something like this for years. Not only does it do a full postcode lookup, it doesn’t require my rather slow page to reload each time.
ianM said,
March 14, 2007 @ 9:10 pm
Thanks a lot for that. I shall try it later, but it is something I am about to try so should get me up and running really quickly. As far as I can see from the two keys, they are identical. Definitely worth a digg.
Tim said,
March 16, 2007 @ 12:29 am
Hi thanks for your post -
I am very much starting out with this - so please forgive what might prove to be the stupidest question going - your gmap.js does not contain the api keys so I was concerned as to the format that they go in as I tried using the same tags as in the html and it doesn’t work - if i take them out I can get a lat long returned but that’s about all ( I wasn’t expecting a lat long without the api keys)
Many thanks again
Dave said,
March 17, 2007 @ 9:23 am
Hi Tom
Great tutorial - any news yet on the caching geocoding - this is exactly what i need.
Keep up the great work.
Thanks
Tom said,
March 18, 2007 @ 3:51 pm
Hi Tim,
I see from your link you seem to be up and running now. I include the API key in the HTML file, not the Javascript file. In the HTML, I first include the 2 Google scripts (with API keys), and then include my gmap.js file, which has my functions.
Dave,
Busy week! I’ll try to get it up in the next couple of days.
Alan said,
March 20, 2007 @ 2:50 am
Hi,
Firstly thanks for this example, it has proved to be extremely helpful.
I wondered if you could perhaps offer your insight too a small problem I am having. I have an array of postcodes which I want to place on a map, which I can do without problem. However each postcode has an associated info popup and I need to somehow feed the data I need to place in the popup to the result callback handler for the specific postcode it belongs to. I assume there’s a simple way of going about this but being a Javascript rookie I can’t seem to dig up any answers.
Chris said,
March 21, 2007 @ 11:53 am
Tom, thanks very much for posting this, very useful information! Got it all working on my site with no problems.
Devblog » Blog Archive » Postcodes to Google Maps on your website said,
March 21, 2007 @ 4:40 pm
[...] Using the default Google Maps API you can only include maps based on longitude and latitude and not on a UK postcode. After a bit of searching I found a brilliant blog post on Tom Anthony’s site that shows you how to use a few JavaScript functions to center the map on a postcode and then place a marker there as well. After following the tutorial I got the map in place but I wanted to extend it so that as the page loads it automatically centers on the postcode and places the marker there. [...]
Tom said,
March 21, 2007 @ 5:20 pm
Hi Alan,
My preferred method for gathering up further information about map markers (for displaying in the info window or whatnot) is to store the informatino in an XML file, then fetch it with an AJAX connection.
You can then parse the XML with the built in DOM functions of Javascript, and grab your information.
I’m going to try to finishing up my caching tutorial today, and then if I have time this coming week I’ll make a tutorial showing what I mean above.
Chris,
Glad to hear it, thanks for the feedback!
Caching Google Maps Geocoder Results | Tom Anthony said,
March 21, 2007 @ 8:46 pm
[...] After my post Geocoding UK Postcodes with Google Maps API I’ve had a few people contact me about caching geocoding results back to a server, for subsequent pages. [...]
Tom said,
March 21, 2007 @ 11:23 pm
The caching tutorial is up now; I hope that it answers your questions.
Harish said,
March 22, 2007 @ 10:36 am
Hi Tom,
I need to pass the raw UK address (not formatted), Could you please help me out on this??
Harish
Online Marketing Blog » Blog Archive » Geocoding Postcodes shouldn’t be hard… said,
March 22, 2007 @ 1:50 pm
[...] Luckily there’s more than one way around the problem, and you can geocode postcodes for free (in one case using more than one Google API). Just look at the list of approaches and tutorials on Google’s own resource page for external geocoding tools. I rather like this method, as it’s relatively simple to code up… [...]
Tony Dillon said,
March 23, 2007 @ 12:59 pm
Hi Tom,
Thanks very much for a great tutorial. Got it up and running in only a few minutes, and it’s saved us a great deal of time, effort and money pursuing alternates. I’ll be extending your code to provide “find your nearest” functionality shortly, and may post the amended code if there’s demand.
Thanks again for a great tutorial. Keep up the good work.
Tony.
Xin said,
March 24, 2007 @ 5:09 am
Tony,
Please do. I’d like to see how you implement this.
I am using Tom’s technique with Ruby on Rails. The plugin I’m using for ‘find your nearest’ functionality is http://geokit.rubyforge.org/.
I’m currently writing up a tutorial on this. I’ll trackback to this post once it is done.
Xin
Tom said,
March 24, 2007 @ 5:37 am
Tony,
That sounds great. I’ve had no call for this yet, but a client of mine may need it soon. I have a couple of ideas for how the algorithm might work, but would love to see how you would implement it!
Xin,
Please do! It would be a great resource!
1000MileJourney » UK Geocoding in Rails said,
March 24, 2007 @ 7:18 am
[...] Tom Anthony’s has written an excellent article called Geocoding UK Postcodes with Google AJAX Search API. [...]
Dave said,
March 25, 2007 @ 5:36 pm
Is any one else having problems getting the ‘Place Marker’ function to work.
Tried this several times and im getting nothing.
Sri said,
March 27, 2007 @ 6:32 am
how to show marker according to country names in .net
rob munro said,
March 27, 2007 @ 12:50 pm
Does this usage abide by royal mail copyright conditions? i.e. can i use it on a corporate intra-net? I guess this depends on weather google have paid for Royal Mails stupid copyright on postcodes latLongs.
do you know anything about this? or have any links to info on it?
David said,
March 27, 2007 @ 10:18 pm
Rob
I think the answer is no.
Read the Google MapAPI Terms and you will see that this sort of thing is not allowed - although you did say intranet and therefore who would know?
You need to check this out for yourself and make a value decision for yourself.
Tom - how about a contact me link on your site?
Eric said,
March 28, 2007 @ 12:56 pm
Rob
I think you need to check out the terms and conditions on Google - be carefull not to just look at the terms for Google Maps - they have to be taken in conjunction with the Terms for Goole its self and as this takes advantage of the AJAX search API you need these Terms as well - thre is some repetition BUT they all have something unique - there is also 3rd party considerations to be taken into account as well - I cat remember who all the parties are but for example NAVTEC and Yell have writes to do with their data…
I see you want it for an Intranet - but as you are then pulling in others info you need to be carefull.
Sorry not to be more supportive but every sitation is different and it depends on what you are trying to do - and the results of this action.
Tom said,
March 28, 2007 @ 1:59 pm
David-
Contact link is a good idea; I’m actually working on a complete site, but a so busy making other peoples websites, I haven’t time for my own!
Hopefully it will be up soon, and I’ll have time to write some more tutorials too.
Rob,
I agree with David & Eric, tread carefully. Though your situation is unique, so who knows. Let us know if you find out for sure.
Eric said,
March 29, 2007 @ 10:09 pm
I found this:
http://www.google.com/intl/en_ALL/help/terms_maps.html
which states
\”Also, you may not use Google Maps in a manner which gives you or any other person access to mass downloads or bulk feeds of numerical latitude and longitude coordinates.\”
might be relevant to some around here….
Dave said,
March 31, 2007 @ 10:39 am
Im still getting the same problem that the PalcceMarkerAtPoint function is not placing a marker.
Re-entered the code several times and re-downloaded the gmap.js file - same thing.
Cleared the cache.. etc etc. Nothing
Any clues what i am doing wrong?
d said,
April 3, 2007 @ 12:08 pm
Thanks for this useful stuff
BTW In step 1, the two google keys appear to be the same
hmnm said,
April 4, 2007 @ 11:07 am
hi, i want search by house number and postcode (like http://www.skiclub.co.uk/skitv/subscription/subscribe.asp ), can you help me?
Prashant Shah said,
April 10, 2007 @ 4:32 pm
Hi Tom,
Thanks for sharing this code with us. I am trying to use your code, ofcourse after replcaing the key, but the map doesn’t load for me. There is no such error but the map doesn’t get displayed on the page. Any idea if there is more to change in your code apart from changing the key? Also can we use this by passing address instead of postcode?
Thanks
Prashant
malcan said,
April 12, 2007 @ 1:17 am
Hi Tom,
I have a couple of sites based on the chauffeur industry and have been looking for a instant quoting system.
I have a simple system at present which is not accurate!
I have got a backend mileage calculator which I can set different rates for pence per mile which is fine.
What I need is an accurate A to B with the correct mileage and take this value and put into my calculator to get a Price.
I recently installed google maps and let people enter in the directions and then ask the customers to enter the mileage shown on the google results and enter the mileage into the calculator to get a price.
It would be nice to have something similar to this http://www.ecourier.co.uk .
I am just playing with a joomla site at the moment and am learning how it all works so many add ons and modules.
Is there a way of extracting the google mileage and to place it into a calculator to get a instant quote or do you have you any idea’s how this can be done!
Any advice would be great
Malcan
links for 2007-04-12 - Bomb.org.uk said,
April 12, 2007 @ 7:26 pm
[...] Geocoding UK Postcodes with Google Map API | Tom Anthony (tags: geocoding google googlemaps postcode AJAX map api JavaScript code webdev) [...]
malcan said,
April 13, 2007 @ 7:03 am
Sorry Tom Put in wrong url
http://www.ecourier.co.uk/eCourierISAPI.dll?quote&id=2555232-37895456
Regards
Malcan
Dan said,
April 19, 2007 @ 7:40 pm
We have tested the code as above but problems with UK data - the response we get is:
-
-
England
-
603geocode
I’m not sure if things have changed since this message was posted?
Any help would be appreciated?
Tks
Dan
photomorgana said,
April 19, 2007 @ 11:09 pm
Hello Tom.
Very good tutorial about UK postcodes. I’m looking for something different. I’d like to have a possibility to read a town or a postcode from the marker placing on the map (I mean latitude and longitude point = town or village). Thanks in advance for an advice.
Raha said,
April 20, 2007 @ 5:01 pm
Its working for me thank you very much. its really charming. Do you know if we can use this in a business website where everybody can access it ?
And also I have one more question. Lets say some one put a post code. Is it possible to recieve a string of street address instead of Long and lat ? if yes where can I find this method ? or what is it ?
Thank you again for sharing this. Lovely.
shinji said,
April 24, 2007 @ 8:36 am
hi Tom,
i had some error while try this code, the error is
GlocalSearch is not defined
can you help me to solve this problem???
thanks.
andrew said,
April 25, 2007 @ 3:46 am
hi, Tom
i had trouble with your javascript code, when i try it in my browser the error says that GlocalSearch is undefined. is it Google AJAX Search API only can used on server in UK??? can you help me for resolve this problems???
Tom said,
April 26, 2007 @ 6:12 pm
Sorry for the slow reply - I’ve been on holiday.
Malcan - I’m not sure. did you get this working? If not it is maybe something that would be worthwhile writing an article about?
Dan - Did you get your problem worked out?
photomorgana - So you’d like to have a map, place a pin in it, and then have a report on what postcode/town the pin is in? Have I got the right idea?
Raha - Yes, using it on a business website is fine, as long as you aren’t charging people to use the map. (per Googles TOS). If you are looking to extract the address information, I’m sure it can be done somehow, but am not 100%. If I get a chance I’ll have a tinker about and see.
shinji - Are you including both the Google script tags *before* including your own Javascript?
andrew - Looks like you are having the same problem as shinji. Do you have an example URL I can take a peak at?
ipunk said,
May 1, 2007 @ 7:27 am
hi, tom!
i was used your script for getting uk postcode in the form. but if the form is submitted the value of latitude & longitude isn’t followed posted. can u help me for this problem?
the script look like :
var a;
var b;
function retValue(){
usePointFromPostcode(document.getElementById(’postcode’).value,
function (point) {
this.a = point.lat();
this.b = point.lng();
}
);
document.form1.long.value = this.b;
document.form1.lat.value = this.a
}
mrben said,
May 1, 2007 @ 4:31 pm
Prashant Shah - make sure that you’ve got your in there, and I found it helped to include width and height in a style.
Tom - 1 question for you - I’m putting my map on a dynamically generated page, and so I don’t want a form, I just want it to drop in the Postcode manually. But I’m having problems getting it to centre and place the marker, perhaps because it’s trying to run the functions before the map is loaded? Any thoughts as to the best way to achieve this?
Tom said,
May 2, 2007 @ 4:39 pm
ipunk-
Move your:
document.form1.long.value = this.b;
document.form1.lat.value = this.a;
Statements inside the callback function (replacing the 2
this.a = point.lat();lines), and see what happens.Good luck
Tom said,
May 2, 2007 @ 4:53 pm
mrben-
There is a couple of methods you could use. The key is the
addLoadEventfunction, which tells Javascript to queue up a function to run after everything is done loading.One method might be to write a
<script>tag into your page (at any point after the<scripttags already there) which has a function to act on the postcode, which is written by your server side script (I’ve used PHP as an example):<script type="text/javascript">
function doStuff()
{
var myPostCode = <?php echo $postcode; ?>;
usePointFromPostcode(myPostCode, placeMarkerAtPoint);
}
addLoadEvent(doStuff)
</script>
The addLoadEvent ensures this is run after everything else is done, and so it should work fine.
Let me know how you get on!
mrben said,
May 3, 2007 @ 8:52 am
OK - I’m making progress. I was almost there - was using window.onDomReady rather than addLoadEvent.
One of the strange side effects was an inability to both place a marker _and_ centre it - it seemed to only take the last argument as the one it performed. So I wrote an additional function into your gmap.js which does both.
Thanks so much for your help
Tom said,
May 3, 2007 @ 1:38 pm
mrben-
Depending on the implementation of
onDomReadyyou are using, you might be able to right anaddDomReadyEventfunction, which works almost identically toaddLoadEventand allows you to queue up several events to happen.Your solution works though, and is probably the more efficient way to do it if you always want to center the map and place a marker at once.
Nice work.
freshness said,
May 3, 2007 @ 3:12 pm
Hi Tom,
This works extremely well, thank you for your efforts. I was wondering if I could pick your brains?
I have a page where PHP spits out DIV tags with unique ID’s (formed from the DB primary key) and attributes for postcode and name of company.
I then use jQuery to parse all the divs in the page which have the attribute showOnPage=”true”, get the postcode attribute and add a marker to the map using your code
However! What I really want to do is add an Info Window to each marker, but I’m struggling with the code. So far, my code will create all the markers and info windows, but the content of the info windows are all the same!
Any ideas on how you could adapt your code to produce info windows?
Thanks in advance, freshness
freshness said,
May 3, 2007 @ 3:13 pm
Sorry, the attribute above should have been ’showOnMap=”true”‘. My bad
Steve said,
May 4, 2007 @ 11:33 am
I’m trying to do exactly the same thing as freshness and having exactly the same problem! Tried modifying the usePointFromPostcode function to take optional parameters with information about each marker that is then passed into the placeMarkerAtPoint function:
usePointFromPostcode(postcode, callbackFunction, optParam)
But with different parameters being passed in I’m finding that the callback function only ever sees the last optional parameter value. But the postcodes are different! I guess this is to do with the way callbacks work and although I’ve got a vague understanding of it got to admit I don’t understand fully. Any chance of a bit of advice on this Tom? Your great work so far on this is really appreciated!
Cheers,
Steve
Tom said,
May 4, 2007 @ 2:56 pm
freshness, Steve,
Try moving the line:
var localSearch = new GlocalSearch();Inside the
usePointFromPostcode()function. This will then create a seperate instance for each search, so the variables won’t get mangled.You can then pass your extra data as an additional parameter to the
usePointFromPostcode()function, which in turn passes it on the callback function. Alternatively, inusePointFromPostcode(), you can tack your extra info inside thepointyou create from the results. In which case the function definition would look like:function usePointFromPostcode(postcode, callbackFunction, infoText)And right after you create
pointyou would add this line:point.infoText = infoText;Now, any functions which use
pointcan access the associated infoText (to create an info window, use as a tooltip or whatever you want).I hope that helps!
Vee said,
May 4, 2007 @ 6:35 pm
Tom,
I have an access database for London, the user hits an address field button, Access then loads googlemaps and goes to the postcode for the address field. But it’s not always accurate.
I would like to be able to get the Geocodes for the addresses in my database, (I have about 4,000) do you know where/what the best way to go about this would be. I don’t want to use this on a website and I don’t really understand how to code ASP/Java/Ajax, etc.
freshness said,
May 5, 2007 @ 11:25 pm
Hi Tom,
Wow, who would have thought it would be that simple! As you instructed, I moved the variable declaration inside usePointFromPostcode() and bingo - my info windows are no longer muddled! Thank you so much, great work.
Tom said,
May 6, 2007 @ 12:20 am
freshness –
No problem - glad you got it all working
Vee –
I’m a little unsure of what you want to do. You *do* want to send people from your Access database to Google maps, right? Or is that a temporary solution? Bombard me with the details!
Vee said,
May 8, 2007 @ 11:47 am
Tom,
I have a fixed number of routes (think delivery vehicles). The routes have waypoints along the way. Here is an example.
Waypoint Postcode:
South St. SE1
Gill St. SE1
Bridge Road SE1
Marshal Road EC1
Great Street EC1
Main Roundabout EC2
At the moment, My database will allow a user to click on any waypoint in any sequence, and will then compile a parsed search list of the addresses for GoogleMaps. When a user hits the ‘Do Route’ button, the program switches to googlemaps, sends the parsed list, and Google Maps then runs the route. It works quite well for streets/places it knows, but when GM encounters places like ‘Main Roundabout’ like the last item in my sample list, GM just falls over. So I figured the best solution is not to rely on postcodes, but use LAT/LON Geo co-oridnates instead.
The problem is that I have a very large table of Addresses and places already in postcode format, so I need a way of translating the addresses/postcodes into a Lat/Lon geo format using an automated method. This is purely for the MS Access internal data records. In other words it is used standalone and is not going to be a website/or backend for a website. (I am not web/http savvy.)
does this make better sense now?
regards
Vee
Steve said,
May 9, 2007 @ 11:11 am
Just a quick note to say a big thanks for your May 4, 2007 @ 2:56 pm post Tom. For some reason just moving the GlocalSearch didn’t fix it with my code but putting the HTML in the point’s InfoText did. Cheers for the fix, you seem to be a man in demand at the moment!
Best regards, Steve
Huw said,
May 16, 2007 @ 5:39 pm
Great stuff! Really helpful & easy to set up - thanks. Configuring it further is still hard for a noob though! Would anyone be able to help http://googlemapsforum.com/showthread.php?t=40 ?
bernard said,
May 17, 2007 @ 7:10 pm
Andy said,
May 22, 2007 @ 2:18 pm
Simply amazing. Thanks for this.
scott said,
May 26, 2007 @ 6:05 pm
hi tom
Thanks for this code.
However, after replacing the keys, the map doesn’t load.
No map, no error messages.
really would appreciate some help - am I doing something really stoopid?
thanks
Scott
scott said,
May 27, 2007 @ 11:11 am
OK - found the problem.
The map div requires size parms e.g:
all is right with the World ..
But, can you help me … I need to grab the lat and lng values to store in a db
- any ideas??
Maxine said,
June 4, 2007 @ 12:08 pm
Hi,
2 qestions - there still appears to be a minor ‘innacuracy’ with the pinpoint locations for UK postcodes (e.g. if I enter a known address I can see that the marker is 100 yards down the road from where it should be…
and secondly.. the map always opens up in ’satellite mode’ - how do i set this so it always goes to ‘map’ view?
regards
Maxine
Avy said,
June 4, 2007 @ 1:20 pm
Thanks dude, I must say you saved my day. I’ve been struggling with UK geocoding but never got a way around it. This solution made more sense than any other solution (obviously a free one).
Cheers,
Avy
Tom said,
June 4, 2007 @ 3:59 pm
scott –
Take a look at the post following this one - it explains exactly what you are after!
Maxine –
Remember this is using postcode only, not a complete address. Postcodes aren’t unique to a single address, but cover a number of addresses. This is the ‘innacuracy’ you are seeing.
As for changing the view being used, in the mapLoad() function see this line:
map.setCenter(new GLatLng(54.622978,-2.592773), 5, G_HYBRID_MAP);
You can change G_HYBRID_MAP to G_NORMAL_MAP or G_SATELLITE_MAP depending what you want.
Avy –
You are welcome.
Ivan said,
June 6, 2007 @ 2:46 pm
Thanks a lot, you’ve saved my time
mani said,
June 7, 2007 @ 12:54 pm
hi,
i am using the same script what you gave below and grap the key using above mentioned url.but it shows the ‘Glocalsearch is undefined’ please help me
this is my key
I am not passing any extra argument to this function
function usePointFromPostcode(postcode, callbackFunction)
Please help me
Thanks
mani
Stew said,
June 7, 2007 @ 9:27 pm
Hi,
I am real problems gettin this to work
I tried the soucre from this page http://www.pets4homes.co.uk/pets4homes/home.nsf/TestMap?openForm&PostCode=bb24jh
and it works fine so I guess my keys/webspace etc are ok
All I get when I try Toms code is buttons but no map?
Any help would be great.
Thanks
Matt said,
June 11, 2007 @ 4:20 pm
Hi,
I’m having the same problem as above. The page loads with the buttons (map, satellite, hybrid, and the pan zoom buttons), but no actual map… just a blank white background.
Tom said,
June 11, 2007 @ 4:29 pm
mani - have you included both the script tags for Google at the top of your page?
Stew, Matt — either of you have an example URL you can post or email to me?
Have you tried copying the files from the demo page:
http://www.tomanthony.co.uk/demo/geocode_uk_postcode/
KD said,
June 14, 2007 @ 5:16 pm
Anyone know whether it’s possible to do the reverse of what’s been discussed above - notably click on the map and get a UK postcode back for this location?
Given there are lots of people who don’t know their postcode and far more who want to use tools that are driven by postcodes but don’t know them for abitrary areas, I consider this is just as vital.
Apologies if this has been discussed before - am new to this
Thanks.
KD
onefix said,
June 14, 2007 @ 7:25 pm
Thanks excellent info. only problem I had was not being able to display the maps correctly but as soon as I realized I needed a styles.css and nofollow.css document worked like a charm.
I am trying to setup the following option, when somebody clicks on a name of a town or village a map is displayed? Unsure how to go about this?? anybody have any ideas or does somebody want to earn some money setting up a script etc for me????
help (at) onefix.co.uk
thanks again seems very accurate postcode finder for postcodes I have tried
onefix : sorry here is site :http://www.cornish.co.uk/cornwall-towns-villages.php said,
June 14, 2007 @ 7:26 pm
sorry here is site :http://www.cornish.co.uk/cornwall-towns-villages.php
ian said,
June 15, 2007 @ 9:24 am
Was thinking about adding this feature for some time but thought it was to much grief up until now.
This is a great piece of work.
Thanks for the time and effort you put into this Tom.
I followed the above guide and it was working on first go, brilliant.
I do have one query however.
If i already have the postcodes and they are being passed to the page via php where would i put these so i could do away with the input fields ? i could echo them into a hidden field or something. but im not sure how to pass the postcode to the gmap.js.
I will figure it out soon. Its a great piece of work. thanks Ian.
Tom said,
June 17, 2007 @ 12:13 am
Hi Tom
Great tutorial!
As UK postcodes aren’t totally accurate for pinpointing a specific building, I have made a modification to allow draggable markers. A listener will then output the new lat and lng to a form field.
http://www.klubbedout.com/ajaxgeo.php
However, once a marker is moved the map won’t re-centre on the new point, the lat and lng (when clicking on show lat/lng) is still the one from the original lookup, also my form field isn’t filled until the marker is dragged.
Can you offer any assistance?
Tom said,
June 21, 2007 @ 6:04 pm
Hi Tom,
A couple of issues I can see:
- You allow multiple markers, so if I am centering the map, which marker should I use?
- The center map button still calls usePointFromPostcode(), so it ignores your updates completely. What you need is a wrapper function on the button, so if there is no marker, it calls usePointFromPostcode() as before, but if there is a marker, it centers there instead.
I hope this gives you a nudge in the right direction.
Kiran said,
June 23, 2007 @ 11:59 am
Hi Tom,
I have followed your tutorial, its gr8. but i couldnt see the Map over there. i have place two Keys and added the GMAP.js in the same path. but i couldnt see the Map as out put. Please have a look and let me know what happened.. Its really URGENT for me.. Please help me Tom.
THanks a lot.
Kiran
S K said,
June 23, 2007 @ 4:43 pm
Hi Tom
Excellent tutorial. I have teh same problem as other ie I’m having the same problem as above. The page loads with the buttons (map, satellite, hybrid, and the pan zoom buttons), but no actual map… just a blank white background.
I’ve used your sample .js file and input form and an API key that works on other files in the directory
Any help welcome
Tom said,
June 23, 2007 @ 6:29 pm
Kiran -
In your html, where you include the map, you are missing an important section of the URL:
http://maps.google.com/maps?file=api&v=2&key=……..
I think that should solve your problem.
S K -
You haven’t copied the styles.css file from the demo page, your map element has not height and width set, you need this CSS:
#map
{
height: 500px;
width: 500px;
}
S K said,
June 23, 2007 @ 10:47 pm
Tom
I gave you the wrong URL. The issue was simply failing to include the styles.css file. Do you know how to set up a facility to click on the map and return the lat, long co-ords.
Kiran said,
June 24, 2007 @ 1:38 pm
Hi Tom,
I have updated file, according to your suggestions but the same effect. It couldnt solve the issue. Could you please look into and letme know..
Thanks in advance
Kiran
Kiran said,
June 24, 2007 @ 1:48 pm
Hey Tom,
Sorry for the Previous Post, It solved my issue.. Thank you so much TOM.
Kiran
Sharron Hibbert said,
June 25, 2007 @ 8:55 pm
Dear Tom
we are currently building a website but have come to a halt re the geocoding, we need something that will provide a return of postcode, street name long/lat co-ords, also whether you can search on postcode info to return a list of available addresses which would then return the long/lat co-ords once selected, we have had some responses but the prices have been too high.
Any suggestions?
kind regards
Sharron Hibbert
alex said,
June 27, 2007 @ 3:27 pm
Hi Tom,
Just want to say what an awesome tutorial! Exactly what I’ve been looking for, and I mean exactly!
Reading through the above posts, I arent sure if someone submitted this exact question and may have worded it slightly different, however:
Your geocoding form adds multiple markers on the map below, one marker for each postcode entered, which then stay on the map until you leave the page. How could I store the postcode entered into a list (txt, MySQL, etc) and then recall this list the next time the page is loaded so that the markers are still available? So effectively you are leaving a mark on a map for anyone else to see.
I have searched high and low to be able to do this and unfortunately to no avail (baring in mind I am a novice at server-side/scripting etc).
Will love ya forever!
Thanks
Alex
alex said,
June 27, 2007 @ 4:18 pm
Ah, I think the caching tutorial answers my question!
However, do you know of a way to make this particular type of map work with sites such as MySpace seeing as MySpace dont allow Javascript (or even PHP)!
Essentially what I would like is a simple form for MySpace users to enter their postcode into a textbox, the postcode would be passed off to my database, then a marker would appear on the localised map along with all the other markers of submitted postcodes (by refresh or something). I know the other MySpace map providers use work arounds via logging IP address and displaying on a map, but this is not accurate enough for my needs of a local based profile that doesnt require worldwide tracking!
This may be slightly off topic to the original map tutorial but any advice in the right direction would be deeply appreciated!
Thanks
Alex
Kiran said,
June 27, 2007 @ 7:21 pm
Hi Tom,
I have an requirement. 1) if need to pass the address in a text field, if i click on placemark or enter it should directly show the location in the Map. Could you please provide me the code or can u guide me on how to do this. one more option for me is 2) a link will there and some address will be associated to the link. If i click on the Link, this should show the location in the Map. Please let me know how to approach to this method.
Thanks in advance
Kiran jagarlapudi
Tom said,
June 27, 2007 @ 7:24 pm
Sharon -
I’m don’t think that Google Maps could do this. With Google Local Search you could get a list of addresses for businesses in the area of a postcode, but not all the addresses. So depending, that may be of some help to you. Otherwise have you tried http://www.postcodeanywhere.co.uk/ ?
Alex -
MySpace won’t allow any Javascript or iFrames, so the only solution you are left with is Flash. I think you could make a Flash form that used LoadVars to send the Postcode entered to your server, which would reply with a list of all Postcodes entered. Then use this very cool solution (which I only just found - am going to check it out more) to provide Google Maps via Flash:
http://www.afcomponents.com/components/g_map/
I think that would almost give you an entirely flash based solution, but I believe it would fall down as you couldn’t access Google Local search and thus couldn’t geocode the postcodes. You’d need to do that server side with one of the expensive databases.
Kiran said,
June 27, 2007 @ 7:57 pm
Hi Tom,
Could you please give me an update on this asap.
I have an requirement. 1) if need to pass the address in a text field, if i click on placemark or enter it should directly show the location in the Map. Could you please provide me the code or can u guide me on how to do this. one more option for me is 2) a link will there and some address will be associated to the link. If i click on the Link, this should show the location in the Map. Please let me know how to approach to this method.
Thanks in Advance
Kiran
Jitesh said,
June 28, 2007 @ 1:11 pm
In your application if i want to print the latitude and longitude on the website rather than giving an alert message…how can i do that…please reply when u get time
regards
jitesh
Stew said,
June 29, 2007 @ 6:58 pm
Hi Tom,
Got my map working (no style css DOH)
Anyhow, I am desperately trying to ‘auto load’ a postcode (stored in a variable) on loading the page.
Any ideas????
Thanks
Stew said,
June 29, 2007 @ 7:43 pm
Hi again,
Managed to do the varible in a postcode.
If i place a marker then center the map, i lose the marker.
In reverse, if a center the map, then place a marker, the map zooms out to some default value. Can I set this default value??
Thanks
Pythoneer » Finding UK places via Google maps API said,
July 1, 2007 @ 7:02 pm
[...] Your royal highness doesn’t like you finding royal places in the royal UK *cough*. How dumb is that. Therefore use a way around, as described very extensively on Tom Anthony’s blog in the article Geocoding UK Postcodes with Google Map API. Thanks Tom! [...]
Izzy said,
July 2, 2007 @ 7:34 pm
Hi,
Great Tutorial, Didn’t have any problems at all.
I have however tryed to use the returned point var to use in the CDirections of the Google Maps API, and for some reason all i get returned is Null for the search.results , Is there anything I am missing?
Think this would be a great addition to the functionality of ur gmap.js file.
Thanks
William said,
July 3, 2007 @ 2:58 am
Hi Tom, thank you for the wonder script. I am now able to retreive many UK addresses and display them on my map.
Matt said,
July 3, 2007 @ 10:10 pm
I think that your solution is obsolete. The Google Maps API offers a way to geocode any UK ADDRESS or UK POSTCODE for free using the GClientGeocoder class in the API! You can pass it any international address, such as “Buckingham Palace, London” or just a postcode and it will return you detailed geocoded information.
FURTHER, Google offers a FREE UK/INTERNATIONAL HTTP geocoding service which returns, via plain old HTTP a nicely formatted XML structure of latitude/longitude and address information for any postcode/zip/address.
It is all here: http://www.google.com/apis/maps/documentation/index.html#Geocoding_Examples
And if you don’t believe the free http geocoding interface, try this address to geocode buckingham palace:
http://maps.google.com/maps/geo?q=SW1A1AA&output=xml&key=ENTER_YOUR_API_KEY
Has everyone else missed this??
Tom said,
July 4, 2007 @ 11:43 am
Hi Matt,
I can assure you that this amount of people have not just missed Google’s geocoder!
However, until recently the geocoder was disabled for both the UK (and others, such as China), and would simply return error 603 (G_GEO_UNAVAILABLE_ADDRESS) and wouldn’t work (as is very well documented by a number of sutes).
FURTHER, I discuss accessing the Google Geocoder via HTTP in the post following this one. It too would return the same error.
I have checked it periodically, and it has always had the same error (confirmed less than a month ago, see for example here). However, it seems you have stumbled across it after they have updated it.
I’m not sure if this update is intentional and can’t find any news about it. If Google had brokered a deal, I’d expect there to be some news about it. I am going to watch this over the next few days, and if it continues to work, then I’ll be sure to update the tutorial.
rickh said,
July 6, 2007 @ 10:38 am
hi tom,
this demo works fine in firefox2 but when i use ie7 i get no marker or anything. even on your demo page when i use the zoom feature using ie7 i just get back a blank map. ive even reset all manufacture setting in ie7 to no avail.
any ideas?
rickh
Mike said,
July 6, 2007 @ 1:01 pm
This is great and easy to use. However I am trying to automate this so when a page is loaded a postcode is grabbed from a querystring and then added to the function e.g usePointFromPostcode(’postcode’, setCenterToPoint). It works great in IE but in firefox it is not working. The error I get is map has no properties. The map obviously isn’t loading in time. I have tried to set timers etc.. but can’t find a way around it. Does anyone have any ideas
Mercurythread said,
July 16, 2007 @ 1:14 pm
Cheers. Have been pulling my hair out with this Postcode thing. Am just away to hack some of the code to make this do what I need it to.
Thanks again
Michael
Chris said,
July 19, 2007 @ 9:46 am
Tom,
This looks like a wonderful resource, which I’m just trying to get my head around. However, is it superceded by Google’s July 6 announcement ‘UK Geocoding Now Available in the Maps API’, or is it complementary?
See http://googlemapsapi.blogspot.com/2007/07/uk-geocoding-now-available-in-maps-api.html
Thanks, Chris
existem.blog » Using the Google Maps API to add maps to your site said,
July 20, 2007 @ 11:05 am
[...] Please visit this tutorial by Tom Anthony which details how to do this. [...]
Gareth said,
July 22, 2007 @ 9:42 pm
Hi, fantastic example!
Just a quick question if you know the answer. I have a database written in MySQL and want to display a map based on the postcode in the db from a recordset. Rather than giving the user the ability to input via a form. Any ideas?
Thanks
Gareth
Mark said,
July 23, 2007 @ 1:09 pm
Thanks for this, I have implemented it on my pets for sale site pets4homes at http://www.pets4homes.co.uk
Craig said,
July 24, 2007 @ 12:59 pm
Hi Tom,
Great information and tutorial.. I’m taking advantage of the help you’ve been giving people in the comments to see if I can pick your brains….
I would like to implement a system where I can check if a route that someone enters on Google Maps passes a certain point (and judge proximity to that point).. I guess it could be done by getting the long/lat of each stage in the route directions and checking that against the point through a loop, but just wondered if there was already a function to check this? Any thoughts would be much appreciated..
Regards..
Alex said,
August 7, 2007 @ 3:48 pm
Hi.
What does the line localSearch.execute(postcode + “, UK”); do?
Hasn’t the point already been created by this stage?
Thanks
Gary F said,
August 14, 2007 @ 2:13 am
Chris, Google’s UK geocoding for addresses is pretty good but I found that it doesn’t work if the address you send it has a building name rather than a number. .e.g. “12 Smith Street, SomeTown, UK” works, but “Cherry Cottage, SomeTown, UK” does not.
Google’s address geocoding can sometimes be more accurate than postcode geocoding. I’d say it’s 50/50 meaning that half the time Google’s address geocoding is better and vice versa. Tom’s technique is brilliant though and it will work every time, unlike Google’s address geocoding. The perfect solution is to use address geocoding and if you get an error from the result try again using postcode geocoding. For large buildings (office blocks, flats, etc) with their own unique postcode you will find that Tom’s postcode geocoding is always bang on the mark.
Tom @ Fivebyte - I love your idea for getting users to update their coordinates using a draggable marker. I’m surprised no one has commented on your work (http://www.klubbedout.com/ajaxgeo.php) it’s really neat.
Gary F said,
August 16, 2007 @ 2:14 pm
My comment was deleted. Here goes again…
Chris, Tom’s clever postcode geocoder is still very important because the official gmaps geocoder for addresses doesn’t work if the address you supply has a building name. It requires a building number which is fine for many residential addresses except some blocks of flats or “Cherry Cottage” etc. The accuracy of Google’s address geocoding is not that accurate surprisingly. e.g. my address is 20m out.
Gary.
Chris Owen said,
August 21, 2007 @ 5:57 pm
Hi Tom/All,
I have had the same problem as others with GlocalSearch not being set. I have noticed however that my url to Google AJAX Search API is pointing to v2 where as yours is pointing to v1. How can I get v1, or do you have a solution using this API?
Peter said,
August 21, 2007 @ 10:34 pm
Tom, congratulations on this. I had a project that wnet on the back burner last year because there was no free way to convert postcodes to locations in the UK - now I can pick it up again
@Tom and @Gary F: now there’s Google local search, Google Maps geocoding and Google Ajax Search, can you shed any light on the difference? I was surprised Tom’s example above didn’t geocode an address - I thought the Ajax search tool would do this? Is there a break-down anywhere of what each is capable of?
Peter
Peter said,
August 21, 2007 @ 10:47 pm
@Gary F: To clarify my question, you say “Google’s UK geocoding for addresses is pretty good but I found that it doesn’t work if the address you send it has a building name rather than a number.”
What approach do you use for such buildings, if you don’t kow the postcode?
Tim said,
August 22, 2007 @ 11:29 am
Thanks - a great tutorial.
Have you come across the little problem of the geocoder treating postcodes with “st”, “nd”, “rd” or “th” as if they are addresses with 1st, 2nd, 3rd, or 4th? Working this out now…
Tim
Set best view for markers said,
August 25, 2007 @ 4:09 am
I have some markers on the map. I want to set best view for these markers (we can see all of these markers with the best view). Please show me the way to implement it.
Thanks,
Manjit dahiya said,
August 28, 2007 @ 7:06 am
Hi Expert
can anybody give me code in server side scrtip like C# or vb.net
Thanks in advance
29 Coolest Custom Search Apps Built on Google said,
September 1, 2007 @ 4:29 am
[...] Geocoding UK Postcodes – Step by step instructions for using the Google AJAX Search API to geocode UK postcodes so you can create Google Maps displays. [...]
links for 2007-09-03 said,
September 4, 2007 @ 12:19 am
[...] Geocoding UK Postcodes with Google Map API | Tom Anthony (tags: geocoding googlemaps) [...]
29 款基于 Google 的超酷自定义搜索应用 said,
September 4, 2007 @ 12:25 pm
[...] - Hoctro’s Place- Search Mashups- Google AJAX Search Plugin【自定义搜索引擎】- Atlas- Babelplex- Windsports- FeedSearch.net- FoxyTunes- Librarian Chick- Mashed Tickets- Oddflower- Searchthebeat- Stylehive- The Recycling Center- Tips-Search- SuccessForce- ccFotos- UniCommunity【电子地图的 Mashup】- The unofficial database- TrekMap- Two Minute World- Wines and Times- Geocoding UK Postcodes- Generate a Local Map Search【Google】- Google AJAX Search for iPhone- Google Map Search [...]
myspace hide comments box codes said,
September 18, 2007 @ 9:13 am
myspace hide comments box codes…
myspace hide comments box codes…
Pragnesh said,
September 18, 2007 @ 1:30 pm
hi ,
i am trying this code in asp.ner master pages.
but its giving object not found error.
can u hel me…??
thanks
Praveen said,
September 20, 2007 @ 12:24 pm
Hi Tom,
Thanks for your code, it really helped me a lot.
Now what am wondering about is, is there a way to find distance for example say the user searches for hotels in Glasgow and you get list of hotels sorted according to its distance from Glasgow.
I dont think i made myself clear there,
I have a requirement for search functionality which takes user’s input either in form of postcode or name of the place. Then that info is used to find the hotels in that locality. If my client doesnt own any hotels in that locality, instead of saying there are no hotels around I would like to show a list of hotels nearby the user’s query. Also it would be better to show distance from the queried place to all hotels nearby.
To my understanding this needs the GeoCoding of the place queried and then display the place in the map then with “calculated distance” the nearby hotels could be sorted out.
But am not sure whether am in the right track, please let me know if that is possible or if there is another way am open to suggestions.
And one last question — is there a way to still calculate the distance in javascript disabled browsers?. This seems quite achievable as google maps do this in some strange means(atleast to me). If possible how?
Thats it from me!!
Thanks
Praveen
google mapquest said,
September 23, 2007 @ 2:15 am
google mapquest…
We are exceedingly pleased that you have stumbled onto this web page about yahoo maps….
Dawei said,
September 25, 2007 @ 11:51 am
well, very nice
Lisa said,
September 26, 2007 @ 8:36 am
Hi Tom,
It seems to be a very good solution.
I want to know whether we can use it in a similar manner to use zip codes for other countries like US etc.
Thanks,
Lisa
google » Geocoding UK Postcodes with Google Map API | Tom Anthony said,
October 7, 2007 @ 6:33 pm
[...] gurusblog wrote an interesting post today onHere’s a quick excerptTony [...]
Vee said,
October 22, 2007 @ 10:04 pm
Hello Tom,
I was wondering if you could give some pointers on whether it is possible to get googlemaps to output a list of street names and generic postcode (eg: WC1 or NW2) within a given (user defined) distance based on a given postcode.
can it be done?
Dan said,
October 24, 2007 @ 8:35 pm
Hi Tom,
I came across your blog while looking for a solution to a problem I am having with UK Geocoding. I had previously been using the GClientGeocoder from the google maps API to map UK postcodes.
As of yesterday this was working great, however as of today it seems that google is no longer returning results for UK postcodes.
I was just wandering if you were aware of this and if you knew anything about it?
Emil Nenov said,
October 25, 2007 @ 10:08 am
Hi, I found the same that map UK postcodes doesn’t work from yesterday, does anyone knows something about that, is that temporarily or …
Regards,
Emil Nenov
Mike said,
October 25, 2007 @ 10:52 am
I have a directory which gets the postcode from a querystring in .net and geocodes for UK this has also stopped working i keep getting Postcode not found?
Dawei said,
October 26, 2007 @ 12:10 pm
Hi everyone, I got the same problem, it’s seems like google has been changed something on their end, which always returning the post code not found
Eric Johnston said,
October 26, 2007 @ 12:44 pm
It is some kind of bug.
It still works approximately if you omit the last letter of the postcode.
Best regards, Eric.
Ed said,
October 26, 2007 @ 2:42 pm
Hi
Could you show us the inline code (for php) required to implement the functionality to return glat/glon? Google seem to have withdrawn the http request method for quick postcode to glat/glon functionality.
Many thanks!
Luke said,
October 30, 2007 @ 9:27 pm
Hi Tom,
Excellent tutorial, Just wondering if there is any way you can also extract address details? for instance is it possible to;
Enter Uk Postcode->Get the Geocode Coordinates-> use the coordinates to get address details…such as town/County and street if possible?
Paul said,
October 31, 2007 @ 5:49 pm
I have just found you can get some address details using:
var town = localSearch.results[i].streetAddress;
var city = localSearch.results[i].city;
var region = localSearch.results[i].region;
Now the UK postcode geocoding has been stopped i have come back to this to pick them up
Pete said,
November 1, 2007 @ 4:30 pm
You’ve probably noticed that Google Maps have withdrawn their geocoding service for the UK now (within the last week or so).
I have a CSV file containing a complete list of UK postcodes, along with lat/long - around 2.5 million entries in total - if anyone’s interested: http://linuxbox.co.uk/postcode_database.php
Stephen said,
November 2, 2007 @ 12:53 am
Hello.
I keep getting a Javascript error of ‘localSearch has no properties’. Is this related to one of the latest posts by Pete saying Google have withdrawn their geocoding service for the UK?
I noticed your demo page still works and I tried copying and pasting the HTML source and altering the keys to mine but then I get no map.
Any thoughts appreciated, Ste.
Stephen said,
November 2, 2007 @ 1:26 am
Please ignore my last post. For some reason the Javascript generated from Google Maps when requesting a key is slightly different to the Javascript you use, and I was copying and pasting from Google. When I used your exact script source from the demo and just replaced your key with mine it worked fine.
But I do have a second question: How would I default the map to a position depending on a PHP database result. I have tried using the following code in the section:
usePointFromPostcode(”tf3 3at”, setCenterToPoint);
But this doesn’t change anything. I just get the usual view of the UK on load.
Regards,
Dan Player said,
November 5, 2007 @ 5:39 pm
Hi all,
Can anyone tell me how I can use this code to generate directions from a point already marked on the map. I want to be able to have people put their postcode into a box and get directions to the church and hotel for my wedding. Ideally I’d like to be able to have them put their postcode in and then it gives directios to the church then to the hotel in one list. It used to work before Google took away the postcode function. Here’s a link: http://www.moatway.force9.co.uk/budget.html
Thanks in advance.
Dan
raghav said,
November 12, 2007 @ 11:59 am
Hi all,
We are working on mashing up GoogleMap API in one of my project. We are finding difficulties in getting the correct location(lat & long) for UK postcodes. There is a significant difference with the Lat /Lng what I get from Geocoder and the one which I get from Isharemaps. For some of the codes, it is unimaginable. Is there any way to get correct lat & Lng through Geocoders with some Degree corrections on the latitude & Longtitude. Also I am looking @ a webservice instead of maintaining the whole database with me.
I found an article which tells me on getting the Correct Lat & Lng with some delta error corrections. But of late, couldnt find that article.
Pls suggest as I am in the middle of this project.
Dan said,
November 15, 2007 @ 10:54 am
Hi Tom,
Wondering if you can help?
We are looking at trying to get an address finder. So you type in your postcode click search and it returns a list of address that are linked to that postcode, containing the house numbers, street name, town and county.
Just wondering if you have done anything along these lines?
Thanks in advance,
Dan
David Savage said,
November 19, 2007 @ 11:07 pm
Hi Tom, and all
I am using a db query to return a postcode.
The usePointFromPostcode function works to place the marker in the correct place, but the map.setcenter just does not work for me.
map.setCenter(new GLatLng(54.622978,-2.592773), 14);
which obviously is Tom’s default setting (which works) - but how do I center the map around the marker?
I try map.setCenter(new GLatLng(point), 14);
map.setCenter(new GLatLng(marker), 14);
map.setCenter(point, 14);
map.setCenter(marker, 14);
map.setCenter(new GLatLng(resultLat, resultLng), 14);
but nothing works… any ideas?
Thanks
Dave
Jack wang said,
November 21, 2007 @ 8:08 am
To CEO: Brand name of tomanthony
Dear CEO,
We are Shanghai Ujane Information Technology Co., Ltd, a domain name register organization in China. We have something urgent to confirm with your company. Because we formally received an application from a company named Lexiao (Hongkong) Investment company. They are applying to register “tomanthony” and so on as Internet Brand name and CN domain name through us. Now we are in charge of this matter. In order to keep other party from using these domain names, we hope to get your confirmation about these domain names’ registration asap.
I’m looking forward to your prompt reply. You may ask someone in your company who is responsible for intellectual property right matters to contact us,or you can let the trademark office in China contact us directly as soon as possible.
Best Regards
Jack Wang
Tel: +86-21-26505825
Fax: +86-21-54243677
Mobil:+86-15800712491
Skype ID: edison.zhang88
Email: jack.wang@ujane.cn
Kai Jin said,
November 27, 2007 @ 3:52 am
The statement
Jack wang said,
November 21, 2007 @ 8:08 am
To CEO: Brand name of tomanthony
Dear CEO,
We are Shanghai Ujane Information Technology Co., Ltd, a domain name register organization in China. We have something urgent to confirm with your company. Because we formally received an application from a company named Lexiao (Hongkong) Investment company. …
This is a scam.
Middle East B2B said,
November 27, 2007 @ 6:50 am
Nice Example liked it….!
Aaron Whiffin said,
November 30, 2007 @ 4:47 pm
One of the best tutorials I’ve ever read
Many thanks!
colin said,
December 12, 2007 @ 5:26 pm
Hi,
I have just started using the API to pinpoint locations in the local area. I am using the GClientGeocoder() class in order to pin point addresses using the uk postcode. All works fine apart from when I use the point() returned by the getLatLng() method to setCenter() the marker on the map is located at the top left of the map control!! I have tried to center using the GetLatLngBounds() but it still remains in the top left corner of the control.
Any help would be appreciated.
Colin
Adam Liptrot said,
December 12, 2007 @ 11:59 pm
Thanks for this Tom - I’d found the geocoding included in the API to be a bit unreliable for UK postcodes. This solution however is spot on!
Shane said,
December 14, 2007 @ 4:37 pm
Great tutorial. I’ll be using it on a forthcoming site. Many thanks.
Study said,
December 15, 2007 @ 3:27 pm
That’s great example. I think we can also use web API provided at geonames.org. I seen using it on http://postalcode.globefeed.com/UK_Postal_Code.asp
Holiday Rentals said,
December 17, 2007 @ 12:18 pm
Very nice found you on google and answered exactly what I wanted to know. Many thanks.
Anshumaan Bakshi said,
December 24, 2007 @ 1:53 pm
Nice script……..it really works.
Thanks for the help
AB
postal codes said,
December 27, 2007 @ 12:12 pm
Search UK Postal Code (PostCode) of Place & City names in UK (Zip code, Postcode). Postal Code
Rehmanab said,
January 3, 2008 @ 3:07 pm
Thanks..
gareth said,
January 3, 2008 @ 7:15 pm
Just what I’ve been looking for,
Thanks for the effort.
Matthew said,
January 8, 2008 @ 6:58 pm
Fantastic brilliant solution
Property for Sale said,
January 9, 2008 @ 11:40 am
Hi there, I am making a property website and want to add this in my website. When user click on some property details it should show map with that property postcode. How can i pass postcode using php and fit in this script. thanks
Property for Sale said,
January 9, 2008 @ 10:14 pm
I am stuck. Basically dont know much about javascript. I have add all code using my own keys. But page coming is giving error and shows blank. Javascript debugger says localsearch is null.
Also what I have to add in html file. Is there someone can share its html file. I only need to work for one postcode then i will configure for autogenrated postcode values. thanks
kan said,
January 10, 2008 @ 6:30 pm
Hi,
how to get direction if I have got longitude and latitude for two places?
John Savage said,
January 13, 2008 @ 10:25 pm
We are losing our workplace car park in the next few weeks. I am looking for a way to gather postcodes of colleagues at work and pour them into the Google map software in order to display, by way of pins, all employees who want to take part in a car sharing scheme. The idea being that anyone in work can see at a glance, the location of other employees who live nearby… a real good use for this kind of software don’t you think… any ideas anyone.
Nick Gilbert said,
January 15, 2008 @ 4:47 pm
Although google now have a UK geocoding service available, since it’s launch they seem to have massively downgraded the accuracy of the service making it useless for most purposes. See here:
http://googlemapsapi.blogspot.com/2007/07/uk-geocoding-now-available-in-maps-api.html
Try comparing the two systems - the test page on the link above, and the test on *this* page. The method described on this page still seems to return accurate locations, but the Maps API Geocoder seems to return data which is up to a kilometer out.
I wonder why they’ve only degraded the accuracy of ONE of the APIs? Does anybody understand why they’ve done this?
Cars for Sale said,
January 18, 2008 @ 9:05 pm
Good tutorial to learn. I am looking for something similar to implement for one of my site. Will see how it goes.
Vic said,
January 21, 2008 @ 11:35 am
Excellent job Tom - very helpful.
So here is one more thank you to add to your already long list!
Keep up the good work.
Vic
James said,
January 22, 2008 @ 11:28 am
Hi Tom
Great little function, just one thing I am trying to pass info from a db to pop into the popup box for the marker. Just not sure how to pass the info.
Here is the code I am using:
var loc = ”;
var car = ”;
usePointFromPostcode(loc, placeMarkerAtPoint)
The var car is what I want to be displayed in the popup box next to the marker.
Thanks for help in advance. James
jude said,
January 26, 2008 @ 2:02 pm
looking for a lady from 23 to 48 for serious relationship.i’m 23yr.please contact through my IM judox4u@yahoo.com
Zn Studios said,
February 4, 2008 @ 11:20 am
Hi - I am getting the “map has no properties” error, its driving me mental - anyone have any ideas??
Bluebarnabus said,
February 28, 2008 @ 6:02 pm
My experience of using the Google Maps HTTP Geocoder for UK postcodes is that it is only uses part of the postcode, for example, XX2 1AN, XX2 1BB and XX2 1XY (if such postcodes exist) would all return the same lat/long values.
You might find MultiMaps offering is more accurate.
b.ramprasad said,
March 10, 2008 @ 2:41 pm
i am using google map for showing path for two places using my own points. when i am using this “Geocoding UK Postcodes with Google Map API” i am not able to get the path. waht to do
Rachel said,
March 19, 2008 @ 7:11 pm
I’m trying to get a map of the DL12 postcode area. Will doing what you suggest ge theis for me?
lookup reverse phone number said,
March 20, 2008 @ 7:05 am
lookup reverse phone number…
Which cell reverse phone lookup providers are you relying on? There are dozens of cell reverse services but you want to make sure you’re using the most accurate information available, right?…
angel said,
March 21, 2008 @ 2:54 pm
Hello,
Could you please provide me some guidance regarding how exactly link gets formed
wen you enter any street address in the address bar of web browser?
Does any API do this whole function of locating that place? Actually I am new to all these things, so I dont have much idea about this.
Thank you.
Chandra said,
March 31, 2008 @ 3:07 pm
Hi Tom,
I have found the tutorial to get the marker up very useful especially because I’m not a pro at javascript.
This will give you an idea on what I’m up to.
‘http://mimtech.pepperio.net/contactus.html’
However, I’m not able to get the FROM functionality on my site working.
If you have a look at the URL above, you see a set of hard coded directions to my office. I’m trying to get this to look a bit more dynamic using a FROM - TO functionality of the maps. I have two options of design to do this:
1. To have the map by default as it is just now when the page loads and then giving an option at the bottom to get the use to type in From and To. The submit resulting a list of directions.
2. This option is to have the default map on loading of the page. Below the map there is a From input box. On submit it shows directions from the typed in Address / POSTCODE to my office (This is coded in the script).
I would like to put more emphasis on the use of “PostCode” in the “From” field.
Here is are some bits and pieces of the script:
if (GBrowserIsCompatible())
{
var map = new GMap2(document.getElementById(”map”));
var panel = document.getElementById(”panel”);
var dir = new GDirections(map, panel);
map.setCenter(new GLatLng(55.863741, -4.24171), 14);
var marker = new GMarker(new GLatLng(55.863741, -4.24171));
map.addOverlay(marker);
var html=” ” +
“MIM Technologies Ltd” +
“141 St James Road, G4 0LT” +
“Tel: (0044) 0141 3038239″;
marker.openInfoWindowHtml(html);
map.addControl(new GSmallMapControl());
}
I have tried various other functions but had no success. Can you please help me with this? Any help is appreciated.
Just to add that I’m using a CMS called Pepperio to do the website.
Thanks!
Chandra
Postcode Finder said,
April 4, 2008 @ 1:30 pm
We’ve been giving this a go, but found there was a real lack of a decent free postcode finder in the UK in the first place - which we needed for some data in the first place. So we didn’t have much to work with.
When our planned tool is complete we’ll post here again.
vashisht said,
April 5, 2008 @ 8:51 am
Nice one!!
Can we have some workaround to use this server side so that we can store the GECOCODES in storage file and then display the multiple address at same time on the map.
e.g i have multiple office location in UK, and i need to show them at same time on map.
Robert Krueger said,
April 10, 2008 @ 12:32 am
Hi Tom,
Can you suggest any of these third party services that you referred to?
I have given my programmer your URL to take a look at your Google solution, but I would like a backup in case he sees a problem.
Thanks,
Robert
Joe Turner said,
April 10, 2008 @ 10:54 am
Used this code for generating a map recently to show local stockists of a product. Have a database of postcodes to find the nearest 10 stockists, and then use their postcodes with this code to plot pins on the map.
So using the AJAX function I just ran a loop for all 10 stockists. The pins are plotted fine. All brilliant!
Then tested in the dreaded IE! Some of the bubbles had swapped marker. No idea why at all. I bodged a function to delay the loop for half a second before running the next postcode search and what do you know it works now.
Any ideas?
Anti-Spam said,
April 10, 2008 @ 8:30 pm
Thanks for this. Very clear and understandable, helped me a lot. In fact it helped me get a job.
Tom said,
April 13, 2008 @ 9:38 pm
Thanks, this helped me a lot.
steve said,
April 15, 2008 @ 11:33 am
Thanks Tom - this has inspired me to add a new feature on a website. I would like users to submit a form to a php function that writes a postcode to a text file and then a point is display on a google map on another page. Can you possibly give me any ideas how this might be done.
The idea is that people pledge to help with global warming and their pledge is marked on the map!
Digital Pen said,
April 22, 2008 @ 2:25 pm
Can this method return street level info as well as postcodes from WGS84 coordinates?
Alex Poole said,
April 28, 2008 @ 10:45 am
Excellent & elegant example, thanks. This appears massively more accurate than Google’s much-vaunted “native” geo-coder. I wonder whether they’ve made it innacurate to keep the Royal Mail happy or something. Regardless, this is excellent, cheers again..
Just need to code up a server-side version now
Andy Newby said,
April 30, 2008 @ 10:43 am
Hi,
First of all - thanks for this code - It *almost* does what I’m trying to achieve
Basically, I want to use this - but actually pre-populate it, with a selection of Postcodes.
I’ve tried adding this into the JS:
localSearch.execute(”rh12 3he, UK”);
localSearch.execute(”rh14 9jl, UK”);
…but that doesn’t work.
Anyone got any suggestions? Heres an example of what I’ve tried:
http://www.gossamerlinks.com/testing_geo.html
TIA!
Andy
Nic said,
May 3, 2008 @ 7:11 pm
Does this all mean that its possible to do this:
Have a customer visit a web site and enter thier post code, then have google work out the distance from an office and send it back to the web site to see if they are too far away (say over 50Miles for example(?
Because that would be very cool.
interesting code snippets » Blog Archive » Geocoding UK Postcodes using PHP said,
May 12, 2008 @ 2:13 am
[...] Geocoding UK Postcodes with Google Map API [...]
Rob said,
May 19, 2008 @ 11:31 am
Grewat code works well.
My question is:
I am looping through a database mapping the post codes, but I want to have an Information Window for each post code, how do I do this?
naimulah said,
May 20, 2008 @ 11:31 am
Hi Anthony,
I am looking for a way to find the postcode for a lat/long. Any ideas if i can acheive this and how?
Many Thanks
seeta said,
June 11, 2008 @ 10:37 am
I would like to thank you for coming up with an genius bit of coding and sharing it with the rest of us, so that we may continue and build and adapt for our own applications.
flowerdaddy said,
June 12, 2008 @ 11:17 am
Hi, thanks for this post.
This is much better than the Google geocoding API.
The long and lat that are returned are far more acurate than just putting your postcode into the geocoding api.
I will be using this technique on an estate agency website which I’m currently building.
It will be going live at http://www.sellinghouses.co.uk next week some time (w/c June 16) in the mean time you can sneak a preview at http://www.thetaylors.eu/properties.asp
Many thankd for the excellent post.
flowerdaddy said,
June 12, 2008 @ 11:19 am
Sorry, the preview pages are at http://www.theonestopphoneyshop.co.uk/properties.asp
Thanks
http://www.inet-designs.co.uk
Sony said,
June 15, 2008 @ 4:19 pm
Thanks Tom for a great tutorial in geo coding. I’ve successfully managed to incorporate it into my site, but now I have another (I hope simple) problem.
Follow the link to view a property and you will see that the map tiles are not loading up correctly and the map page simply refuses to centre on the point. It always appears just off to the top left.
Can anyone help?
http://www.ukhousing.com/
Alec said,
June 16, 2008 @ 7:43 am
Thanks for the great tutorial, unfortunately it only encouraged me to continue down the blind alley of trying to achieve something similar to what Malcan was looking for back in April 2007.
Eventually I looked around for another solution and what I couldn’t achieve after weeks of messing about with Google Maps was achieved with a solid afternoon’s work using Microsoft Virtual Earth. It’s slower and it’s Microsoft but it works! I just wish I could have achieved the same thing with Google Maps. http://www.anywherecouriers.co.uk/tariff1.html
Winzeep said,
June 18, 2008 @ 4:49 pm
Hi,
Sony : got the same problem a few days ago. It happens because you have your map loaded in an hidden div so the API cannot find your element’s width and height, thus it uses an element 0×0 and that’s the reason why it’s centered on the top-left corner. You can solve the problem by forcing the width and height in your function when you create your GMap2 object :
new GMap2(container, {size:new GSize(width,height)});
Hope it helps
Guy Roberts said,
June 23, 2008 @ 10:34 am
For the people who had trouble with a Javascript error GlocalSearch not defined, paste your key directly into Tom’s example.
()
If like me you use the whole line that google gives you, they will set you up with a slightly different way of loading classes and GlocalSearch will not be in scope.
See http://code.google.com/apis/ajaxsearch/documentation/#The_Basics for more.
FREE SpiderWeb Marketing System - www.TheSpiderWebSystem.com said,
June 30, 2008 @ 2:07 am
FREE SpiderWeb Marketing System - http://www.TheSpiderWebSystem.com...
Live Search: \”Fortune High-…
steve said,
July 4, 2008 @ 5:46 pm
Hi
Does anyone know how I can make this example query and load load automatically?
I have the postcode already extracted from a database and just want the map to appear when a link is clicked.
The link is someones name - when their name is clicked a php programme runs pulling their details and postcode from a db.
I never use javascript so dont know how to automate js functions
thanks
Steve
steve said,
July 4, 2008 @ 6:12 pm
Just to clarify - the map is displaying with the default co-ordinates set up in gmap.js. I dont import gmap.js I have it as a js routine internally to allow me to populate my_postcode variable dynamically from php & database, but dont know how to get
usePointFromPostcode(myPostcode, setCenterToPoint);
to run automatically,
Thanks
Steve
GIL said,
July 7, 2008 @ 3:46 pm
Hi,
Can someone tell me how to I change the deafult map that I get in the sample code of google? I would like to have a map of the uk in my website.
Thanks and regards,
Gil
JR said,
July 15, 2008 @ 2:38 am
Is it possible to do the reverse of this? I want to feed an address (either city, street, or even long/lat coordinates) and have Google report back a FULL UK postcode. Does this technique work around Royal Mail’s deathgrip on the copyright?
anil said,
July 26, 2008 @ 10:54 am
Hi Tom
I need u r help. I want to add google map in SEO. After finding my website this map should appear along with my keywords and web address. Please help me in this probelm.
keith said,
August 30, 2008 @ 12:01 pm
Thanks dude, spent a while trying to get the lat lng for a postcode to go to a festival. Your website helped me!!
Tom whitbread said,
September 2, 2008 @ 8:09 pm
Hi Tom,
I have been trying to implement your google maps api on a page load so that a postcode I have passed it displays in the map.
Problem is I get an error saying the map object is not defined. I beleive this is down to a scope issue, but there is not in your example. So I am very confused as to why there is a problem when not calling it from a form.
In firebug I get
map is undefined
[Break on this error] map.addOverlay(marker);
Now what can I do to get this working?
Thanks for submitting such good work open source, I really hope we can squash this bug and get it working for my application
Thanks again
SAIPRASAD said,
September 19, 2008 @ 6:52 am
super
Karl said,
September 20, 2008 @ 7:03 pm
Its not accurate. Both mine and my partners houses are approx 200 meters away according to your scripting, however if I use google directly its perfectly accurate.
Eric said,
September 23, 2008 @ 7:23 pm
Tom whitbread said, September 2, 2008 @ 8:09 pm
map is undefined
[Break on this error] map.addOverlay(marker);
I encountered this same problem. In my case it was beacuse i was calling the
usePointFromPostcode(’postcode’, placeMarkerAtPoint);
in the body tag onload of the document. With gmap.js it checks to see if onload has been set to a function. however if you put the onload in the body tags then it the typeof is not a function and it runs
window.onload = func;
Which calls the mapLoad(). However this gets overridden by the body tags onload and so mapLoad() does not get called and doesnt get instatiated. That is why you get map is undefined.
Basically you have to be careful where you call usePointFromPostcode from. You must make sure that mapLoad() gets called prior to usePointFromPostcode.
so i simply removed the
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != ‘function’) {
window.onload = func;
} else {
window.onload = function() {
oldonload();
func();
}
}
}
addLoadEvent(mapLoad);
in map.js
and added in my code instead:
window.onload = function() {
mapLoad();
usePointFromPostcode(’postcode’, placeMarkerAtPoint);
}
as i say this only happens when there is a conflict of the onload is defined in the body tags, or if you do use window.onload = function() in your file to load other scripts you have to change in addLoadEvent
else {
window.onload = function() {
oldonload();
func();
}
}
to
else {
window.onload = function() {
func();
oldonload();
}
}
You see in the orginal script it calls your onload function first rather than the func() (which is the call to mapLoad() which initialise the map varibale) and so the map variable is not defined.
I hope that clears things up….
Eric
caribbean diving holidays
Tom said,
September 30, 2008 @ 4:24 pm
Excellent tutorial! One thing…. any way to stop the map bouncing you to San Francisco when you enter a random string (ie. not a UK postcode) into the search?? Getting this fixed would definitely stop the headaches!!
Tom said,
September 30, 2008 @ 4:44 pm
Additional bit… try searching for ‘yb’….
Tim said,
October 3, 2008 @ 3:54 pm
Hi Tom,
I’m a complete novice at this and I have some developers building a site for me. I wanted to contact you directly to ask you a few queries, but I couldn’t see any way to do this. Would this be ok?
Tim
Graham said,
October 7, 2008 @ 12:27 am
Brilliant. Just what I’ve been looking for. Saved me hours of work.
Harold said,
October 8, 2008 @ 7:09 am
Top tips, many thanks. I’ve been banging my head against this for a while!
Web Design Company said,
October 15, 2008 @ 8:58 am
Excellent tutorial! very nice guys..
Paul said,
October 18, 2008 @ 12:17 pm
Can anyone tell me if this solution is still accurate. I read that Google were downgrading the AJAX local search due to legal reasons and that it would therefore become less accurate.
Is there any truth in this rumour?
dan said,
October 30, 2008 @ 12:06 pm
i’ve replicated the tutorial exactly but the map doesn’t get created? Has noone else had this problem? I think its to do with the onload business but i’ve tried several ways of calling mapLoad();
It all seems so straight forward and its really frustrating that its just not working! Any help much appreciated!
/// the error;
GlocalSearch is not defined
gmap.js()()gmap.js (line 2)
[Break on this error] var localSearch = new GlocalSearch();
???
used cars for sale said,
October 30, 2008 @ 9:04 pm
Lovely tutorial. Never seen any tutorial like this on the web. easy to use.
Steven said,
November 4, 2008 @ 6:02 pm
Hi Tom, Your tutorial is exactly what i have been looking for in my Honours Project but unfortunatley I cant get it working, I dont even get an error to give me a clue, the map appears on the screen center to where I set but if i search the postcode the page refreshes and the textbox is emptied. Any ideas what could be the problem?
Steven
Tom said,
November 4, 2008 @ 6:13 pm
Dan - have you got both the Google header files included? One for maps and one for local search?
Steven - In the spirit of ‘teach a man to fish’… Install the “Web Developer” Firefox extension and then try this. It has a popup box which provides Javascript errors and is exactly what you need for debugging problems like this.
Steven said,
November 4, 2008 @ 6:32 pm
Yeah I have the web developer toolbar for firefox and unfortunatley for me it has found no errors with my code. I dont think its the syntax as I have copied your tutorial step for step, it’s not the keys either since i can see the map. the problem has me stumped lol
Steven said,
November 5, 2008 @ 10:48 am
Thanks tom, I finally got it, I have been developing this in asp.net and with a little trial and error I discovered I can wrap the map and its elements inside an element that has the attribute runat=server.
Great tutorial. Helped alot.
Any idea how to narrow the search to a particular house number?
Steven
Ian said,
November 7, 2008 @ 12:12 am
Hi
I have a quick query on Google Maps. Is the following statement correct, if so what is the solution to get around this? I.E. How do the likes of http://www.globrix.com/property/buy/edinburgh?ns=true&rd=1&br=buy&qt=edinburgh use googlemaps to plot the accurate placement of homes on the map?
“Google is now capping the number of searches you can do using geocoding which is what is used to convert addresses to long/lat points on the map.
They are doing this to force people to use the actual long/lat code when generating maps”
Ashutosh said,
November 10, 2008 @ 7:59 am
Hi Tom,
I have one query, there is a requirement to display the alternative of city will displayed suppose some one has entered elton as city name then api will display alternative of elton as ELTON- CHESTER- CHESHIRE,ELTON- LUDLOW- SHROPSHIRE,ELTON- MATLOCK- DERBYSHIRE. can we do this with use of this api.
Lee Hayward said,
November 13, 2008 @ 1:56 am
Hi Tom. I’ve been trying to develop a map that A) lets the user first type in their postcode , then B) allows them to move/adjust the position of the marker. Before saving it all back to a database! I’m trying to use your code with this script — http://mytubestop.com/add_marker_test.php — but can’t seem to get it working, I don’t know what the heck I’m doing. So , I’ve put the script back to normal, without your code added and was jut wondering, if you could help me.
If you can also tell me how to stop the user from adding multiple markers, I’d be really chuffed and would gladly give you a mention when my site is full off the ground. I can give you a sneak preview if you email me.
Thanks
Lee
Lee Hayward said,
November 14, 2008 @ 3:52 am
Oh yeah! I love it when I answer my own questions
The Solution to my own problem is here: http://mytubestop.com/add_marker_test.php
Firstly, I’ve made the function placeMarkerAtPoint() dragable. Then I had to add var point = marker.getPoint(); so that the new co-ordinates would be updated on dragend, which for effect I’ve added to the info window.
Try it out. Put in a postcode, click Center Map then Place Marker. Then drag the marker to see the lat/lng variables update !!
John Smith said,
November 15, 2008 @ 11:37 pm
Google’s built in Geocoding may be “over a mile off on some postcodes” but yours is several thousand miles off for others. Newport NP1 for example.
Dick Sykes said,
November 21, 2008 @ 3:09 pm
Tom,
I am just getting started with Javascript and HTML so am on a steep learning curve. I have a map onto which I am loading a handful of post codes from a file. The file contains the post code and a description. I drop into a loop calling usePointFromPostcode for each post code and these come out on the map fine.
I am stuck on adding the description to the marker using GMarker.bindInfoWindowHtml. How do I get the description for each post code through to the callback function so that it can add the description. I have tried a few things but the best I have achieved is for the description of the last post code to appear on all the markers.
saeed ahmed said,
November 25, 2008 @ 9:03 pm
can it run in local host.
Dave Alex said,
November 27, 2008 @ 9:48 am
Hi!
Thanks for guidance. Can some one guide me that how can all this be used in pure PHP. Like only the following URL
‘http://maps.google.com/maps/geo?output=csv&key=$api_key&q=’ is used to get CSV output from Google server for latitudes and longitudes.
cars for sale said,
November 29, 2008 @ 11:37 pm
nice solution. i still cant find anything from royal mail and there price is too expensive that i cant afford.
is there anything i can find for finding street name. like if i enter postcode and find the street address.
chidi onyema said,
December 5, 2008 @ 11:04 am
nice solution Tom. Im not sure what i would have done otherwise, brilliant thanks
Jason Campbell said,
December 6, 2008 @ 3:22 pm
Good Work.
tony said,
December 11, 2008 @ 6:41 pm
hi, i have installed a property management app and need to import a UK postcode csv data file for the map and location finder to work. where can i get this from?
please help with this. thanks for your time. tony
Srihari said,
December 19, 2008 @ 12:39 pm
Hi tom,
Good article and your work is great. First of all thanks for that.
But,
I want to find the distance between two postal codes which are entered in a form with Two textbox.
Waiting for you reply.
Thanks
James said,
December 22, 2008 @ 12:57 pm
Great tutorial, many thanks for this… exactly what I needed.
Rik Beacroft said,
December 22, 2008 @ 10:12 pm
Great article. Was wondering, if you overlay an image over an area of a map, is it possible to work out which towns, countries the overlayed image covers?
Impotence Help said,
December 28, 2008 @ 7:40 pm
Impotence Help…
Help is only ever a click away……
James R said,
January 7, 2009 @ 9:58 pm
Is there any way to plot an outline around a post code or a county or a suburb or a city…within the UK?
Matt Humphrey said,
January 8, 2009 @ 11:55 am
Hi,
I was having immense problems with gettin this to work, I kept getting the Glocalsearch not defined error. This is because you need version 2 of the maps JS and version 1.0 of the API JS. I just viewed the source of this page and copied and pasted the two Javascript references and changed the API keys and it all works fine now.
data mapping said,
January 16, 2009 @ 5:35 am
The Data Mapping engine in Data Transformation Server allows any-to-any transformations between different data formats. It includes complex data functions such as string, math, and conditional operations as well as DB and XML file look-up.
Omar said,
January 18, 2009 @ 11:12 pm
I’ve hard-coded the postcode in to my JavaScript function so it goes straight to that location on page load. But I have been unable to get the marker to be displayed upon page load - does anyone know how to do this?
tx said,
January 27, 2009 @ 4:49 pm
hi, great tutorial first of al!
i just wondered if anyone could help me out on the terms side of things.
say i have a company website which has a database of my clients inc their addresses and i used the google api / ajax to store the long/lat numbers of their addresses in my database that ive returned from querying the google api, does this mean im infringing googles terms & conditions?
on first thought i dont see how you would be, as its not many calls which are made, only when a new client is added, we query google for their lat/long, store it for possible further use with a radius search.
whats peoples view on this???
tx :o)
Oliver said,
January 28, 2009 @ 6:05 pm
Thank you for posting this blog entry, Tom. I found it very useful, and have implemented a slightly adapted version of your map system on the My School Christmas Cards website.
I have found a slight problem, though. The copyright notice at the bottom of the map can sometimes be too long for the map div to contain, and the notice spills out to the left. For example, try centring your map on the postcode SM7 2BQ. The copyright notice appears as follows: “Imagery ©2009 DigitalGlobe, Infoterra Ltd & Bluesky, GeoEye, Bluesky, The GeoInformation Group, Map data ©2009 Tele Atlas - Terms of Use”. In my browser, this stretches across your page margin, right over to the left-hand edge of the screen.
The same happens on the website that I have implemented the system on, except that the notice actually interferes with text that I have on the left of the map.
Is there any way around this?
NickC said,
January 29, 2009 @ 3:29 pm
Oliver - the simple way to get around the copyright text spilling out of the map container is to add an extra CSS command to your map div.
Just add ‘overflow:hidden’.
It’s cheap and cheerful solution but seems to do the trick.
Nick
Josef said,
January 31, 2009 @ 2:44 pm
Hi,
I have a table of UK postcodes stored in a MySQL database that I want to plot on a Google map.
Does any one have any advice on how I could go about doing this? I have read through all the 100s of comments but can’t quite work it all out since everyone has slightly different requests.
Thank you.
Oliver said,
February 3, 2009 @ 10:15 am
NickC - Thanks for the tip! That does indeed stop the text from spilling out.
Andrew said,
February 4, 2009 @ 11:53 am
Great tutorial.
Just going through it now.
Just one questions, I already have a Google Maps API key and have just got a Google AJAX API key
However, looking at your code (demo page) the 2 keys you have are the same code?? Is it the GOogle Maps one or AJAX one?? Do I need the reference to both somewhere??
Thanks
Andrew said,
February 4, 2009 @ 12:32 pm
Its OK, my mistake. Just generated another Google Maps API Key and its the same as the AJAX one
Followed your instructions but not quite working. when enter location or postcode and press center map and place marker nothing happens.
Ideally I want it to enter postcode, press button and it centres AND places marker on location
Thanks
PS - How do you get the “controls” to display - the zoom in and out etc
Spartan Internet said,
February 6, 2009 @ 8:41 am
Thanks a lot for this post. i have been looking for something like this for this month. its post to help me .. Spartan Internet Consulting,
Spartan Internet,
Spartan Internet Marketing Consulting
Mike said,
February 12, 2009 @ 9:12 pm
I have a slight problem
This is my code
Search
function CheckKey() {
if (event.keyCode == 13) {
usePointFromPostcode(document.getElementById(’postcode’).value, showPointLatLng);
}
}
If i enter a post code then click the search button everything is fine. But of I press the enter key which i have captured it goes to the function, but never actually does a new search and i just get the same results returned from the last search. Does anyone know why this could be happening. if i put an alert just before it calls localSearch.execute(postcode + “, UK”); then the alert will come up. As i said works OK on click but not on key down. Has anyone had a problem like this?
function usePointFromPostcode(postcode, callbackFunction) {
localSearch.setSearchCompleteCallback(null,
function() {
if (localSearch.results[0]) {
var resultLat = localSearch.results[0].lat;
var resultLng = localSearch.results[0].lng;
var point = new GLatLng(resultLat, resultLng);
callbackFunction(point);
} else {
alert(”Postcode not found!”);
}
});
alert(’hello’)
localSearch.execute(postcode + “, UK”);
}
Verno Purcell said,
February 14, 2009 @ 10:14 am
Hi Tom
What I need is the uk complete uk postal codes and the longditude
& latitudes numbers to put into our site data base. I personal am not a web designer, so this is what I have been told that I need.
Is this posible to get ?
Vernon
Scott Warren said,
February 18, 2009 @ 5:56 pm
Hi Tom,
This code has been a great tool for our site, however i am having issues with multiple calls the the usePointFromPostcode() function in IE although it works absolutly fine with Firefox. Could you please email me and i will give you access to our website and then we can talk about the issue here. We can also look at providing you some funding for any work you carry out for us.
Thanks
Scott
Ben said,
February 23, 2009 @ 11:18 am
Thanks a lot for this, a legendary bit of work. Added a tag for django template language at: http://www.djangosnippets.org/snippets/1336/
Liam said,
March 5, 2009 @ 5:38 pm
This is an excellent soltion
Classified Adverts said,
March 15, 2009 @ 9:40 am
i have done exactly as you have said … but for some reason i cant see the marker when i click on the buttons … i guess its not working properly … help is needed please. help as i need to integrate it in my classified adverts site.
Cheers … hope it works out ..
Martin said,
March 19, 2009 @ 5:37 pm
For anyway who is a novice like me and need the exact code to have your map load from a postcode stored in session variable - have a look at this link.
http://forum.websitebaker2.org/index.php?topic=12846.0
Absolutely fantastic post by the way, been looking to do this for a long time now
Tino said,
April 9, 2009 @ 10:40 pm
Wow this is great, its really what I was looking for.
I have a slight problem though, on a basic HTML page the code workd fine but when I place it on an asp.net form I cant get it to work.
I read further up the thread and tried what one user suggested, to put runat=server in the controls, i tried it in the input tag and the others too but still cant get it working.
Any one cast any light?
Thanks
Tino
aspx
Tim S said,
April 10, 2009 @ 11:57 pm
heres a little something created with similar geocoding. This is a google / ebay api mashup and pin points used cars for sale via Ebay auction listings. Have a go! http://www.find-cars-4-sale.co.uk/
Tino said,
April 15, 2009 @ 12:46 pm
Would it be possible to provide an example using RESTful interface returning JSON object for ASP.NET C#?
I belive it supports the GET method
Regards
Tino
Jim said,
April 23, 2009 @ 12:51 am
This is great. It also shows great weaknesses in my understanding of javascript.
Try as I might, I can’t figure out how to make the system work off a postcode variable. As stated, onload doesnt work as a method to trigger the map to use a postcode. I cant find a place / modification which loads themap according to a postcode variable either.
I am obviously being thick. Does anyone know/already have a variant of this code which works from a postcode variable passed to the code (or even a hardwired postcode rather than coords)?
Many thanks if anyone can help with this, it is driving me mad…
Jim said,
April 23, 2009 @ 8:52 pm
Oops.
Thanks so much Martin, I failed to see your link (just about as well as I failed to find the information elsewhere!!)! For those looking for the exact code to display a map by postcode variable without a click, as Martin above pointed out, the solution is here:
http://forum.websitebaker2.org/index.php?topic=12846.0
Alec said,
April 25, 2009 @ 2:50 pm
Well thanks to Tom’s tutorial I’ve finally managed to get driving directions with accurate start and end points using the Google Maps API. It’s only taken me a year to work it out.
Here’s an example for anyone struggling with the same thing http://www.anywherecouriers.co.uk/maps/directions-with-uk-geocoding.html
It’s probably not the most elegant solution but it works and I’m happy.
Noms said,
April 30, 2009 @ 4:51 pm
Thanks very much for this article Tom.. I have also made some additions to it like adding reverse geocoding.. getting address details from latitude and longitude.
However, is there a possibility we can create a dll or a webservice that does that.. What i am trying to say since it uses Ajax/javascript that runs only on client side.. can we trick a page into thinking that it has been rendered on the browser to invoke the javascript..
I have been trying to find a way to do that but have not been successful.
Not sure if anyone else has tried it yet. if so do let me know..
stefan said,
May 9, 2009 @ 7:57 pm
great info, thanx
Puppies for sale
Ibrar said,
May 11, 2009 @ 12:15 pm
Hi, thanks for Great tutorial.
Andrew said,
May 12, 2009 @ 3:42 pm
I am have a problem all to piont i put on the map have the same text can some see what i am doing wrong
function usePointFromPostcode(postcode,ref) {
localSearch.setSearchCompleteCallback(null,
function() {
if (localSearch.results[0]) {
var resultLat = localSearch.results[0].lat;
var resultLng = localSearch.results[0].lng;
var point = new GLatLng(resultLat,resultLng);
var marker = new GMarker(point);
GEvent.addListener(marker, “click”, function() {
marker.openInfoWindowHtml(InfoText[ref]);
});
map.addOverlay(marker);
}
else {
/* SKIP THAT PROPERTY CUZ I CAN’T FIND IT! */
}
});
localSearch.execute(postcode + “, UK”);
}
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != ‘function’) {
window.onload = func;
} else {
window.onload = function() {
oldonload();
func();
}
}
}
function addUnLoadEvent(func) {
var oldonunload = window.onunload;
if (typeof window.onunload != ‘function’) {
window.onunload = func;
} else {
window.onunload = function() {
oldonunload();
func();
}
}
}
addLoadEvent(mapLoad);
addUnLoadEvent(GUnload);
Welcome back Andrew here are you jobs for today
var InfoText=new Array();
InfoText[0] = ‘Job No. 3 Name : Price Phone ew’;alert(”0″);
usePointFromPostcode(’wa1 0py’, ‘0′);
InfoText[1] = ‘Job No. 4 Name : 1 Phone 1′;alert(”1″);
usePointFromPostcode(’1′, ‘1′);
InfoText[2] = ‘Job No. 4 Name : Tim Phone 1′;alert(”2″);
usePointFromPostcode(’WA4 0Py’, ‘2′);
InfoText[3] = ‘Job No. 4 Name : a Phone 1′;alert(”3″);
usePointFromPostcode(’WA2 0PY’, ‘3′);
InfoText[4] = ‘Job No. 4 Name : Price Phone ew’;alert(”4″);
usePointFromPostcode(’wa3 0py’, ‘4′);
InfoText[5] = ‘Job No. 4 Name : price Phone 11′;alert(”5″);
usePointFromPostcode(’PO45 2ah’, ‘5′);
InfoText[6] = ‘Job No. 4 Name : aa Phone 1′;alert(”6″);
usePointFromPostcode(’1′, ‘6′);
InfoText[7] = ‘Job No. 4 Name : 1 Phone 1′;alert(”7″);
usePointFromPostcode(’WA2 0PY’, ‘7′);
InfoText[8] = ‘Job No. 4 Name : 2 Phone 1′;alert(”8″);
usePointFromPostcode(’S70 4ST’, ‘8′);
Polskie Firmy said,
May 19, 2009 @ 2:45 pm
Many thanks for this great tutorial! Exactly what I was looking for
Sean said,
May 28, 2009 @ 2:36 pm
I had the same problem as Stew (June 7, 2007 @ 9:27 pm) and Matt (June 11, 2007 @ 4:20 pm)
The page loaded with the buttons (map, satellite, hybrid, and the pan zoom buttons), but no actual map… just a blank white background.
I even followed Tom’s advice and copied the the files from the demo page:
http://www.tomanthony.co.uk/demo/geocode_uk_postcode/
Still no joy.
Then I noticed the htm file ends with
<div id=”map”
I replaced this with
And bingo - it works.
Sean said,
May 28, 2009 @ 2:40 pm
Sorry, code didn’t come out.
I replace id=”map”
with
id=”map” style=”width: 700px; height: 450px”
and this worked
Gumbo said,
June 2, 2009 @ 7:02 pm
Nice, simple and clean.
thanks for a great tutorial.
Cheers!
rob ganly said,
June 6, 2009 @ 10:31 pm
>>but no actual map… just a blank white background.
the reason it comes out blank is because the map is styled [sized] in the css file, and by just copying the source you won’t have this styling info.
the quickest way to remedy this to get the demo working locally is to just put the style inline in the head of your doc.
#map
{
height: 500px;
width: 500px;
}
hope that helps.
rob ganly
JMM said,
June 8, 2009 @ 12:52 pm
Got the code working no problem and thanks very much for providing.
I am looking to embed the map into a PDF created from Coldfusion. When I add in the working code it produces nothin on the PDF.
Anyone any ideas?
Bookmarks for June 8th from 11:12 to 11:38 « what i say // jon burger said,
June 8, 2009 @ 2:17 pm
[...] Geocoding UK Postcodes with Google Map API | Tom Anthony - [...]
Aron Draper said,
June 15, 2009 @ 12:41 pm
I used your code a long time ago and has been working for well over a year but today it ha sstopped working and can see that the one on this site has stopped working too with the same errors fro JavaScript. Im gussing there will be a few people with this issue.
Im currently looking for an answer and will post her eif I find something.
Aron Draper said,
June 15, 2009 @ 2:51 pm
A change must have been made with the API or a Windows update becase all the maps Ive looked at today that used this tutorial have now stopped working.
Ive been trying to find an answer to no avail. The error is that the map doesnt display at all and you get some javascript errors referrign to localsearch and glocalsearch.
Anyone with a fix it would be greatly appreciated.
Julie said,
June 16, 2009 @ 10:41 am
Hi,
I have a small B & B business and when my guests use sat nav to find me it takes them 400/500yds away from me, where there are only two houses. I am one of four and one of them is a pub. Can you help or advise me on how to get this changed. Just spent an hour on google and got nowhere. I’m not very technically minded, so please keep it simple !!!!!
Thank you
Julie
AD said,
June 22, 2009 @ 3:25 pm
I am wondering, does this API actually validate postcodes.
IE:
Apartment/Lodger Website where users need to enter in a postcode, which provides a Google map reference; therefore a Postcode is used to validate the location and create a map location at the same time.
What happens if the postcode is invalid? Will it be able to catch it and display it on the screen (or return it in some other way), rather than accepting it?
Thanks.
Max Manders said,
June 22, 2009 @ 6:22 pm
Hi,
I’m working on a personal site that uses the Google Maps API. The postcode the user submits is used to make an AJAX call to a home grown API that returns among other things, a load of postcodes in XML. I then iterate over these postcodes and place markers for each of them, i.e. all the postcodes that are related to the user-entered postcode.
However, I presume the localsearch performs asynchronously, and as such, some of my postcodes aren’t being geocoded - I believe because the previous localsearch hasn’t returned).
My code is something like:
[code]
for (var i = 0; i < stores.length; i++) {
var postcode = stores[i].getElementsByTagName(’postcode’)[0].childNodes[0].nodeValue;
usePointFromPostcode(postcode, placeMarkerAtPoint);
}
[/code]
There are 5 postcodes in my XML being output by Firebug, but only the first and last are successfully geocoded. Any thoughts?
Adam Binno said,
June 24, 2009 @ 1:31 pm
Hi,
Thanks for the great tutorial and demo. I would have never thought to use the ajax search with google maps but it seems to work pretty well, not sure how accurate some of the results are which are returned by google tho.
Thanks
Martin Babcock said,
June 25, 2009 @ 7:08 am
Do you wish you could increase your online leads? Getting a 1st page Google ranking is easier and more cost-effective than you might think. We have helped a lot of businesses thrive in this market and we can help you! Simply hit reply and I’ll share with you the cost and the benefits.See you at the top!
sophie said,
July 23, 2009 @ 10:08 am
Hello, i tried to find my friends house by using her postcode on google and it didnt work…:(
Michael said,
July 29, 2009 @ 11:42 am
Tom,
A FANTASTIC tutorial there. I’m very impressed and have had little to no problems in implementation. However (you KNEW that was coming)… There is still a MASSIVE problem with accuracy in the data I’m getting back from google. If I may give an example: GU5 0HF comes back as 51.193548,-0.557244 when it SHOULD be 51.193608,-0.556999.
Is there something just inherently WRONG with googles data?
Me said,
August 4, 2009 @ 10:38 am
Michael, according to Royal Mail (who should know) GU5 0HF is High Street, Bramley, which Google correctly positions at 51.193548,-0.557244. 51.193608,-0.556999 is in Windrush Close, Bramley, which Royal Mail identifies as GU5 0BB. Google reverse geocodes this to 23-37 Windrush Close, Bramley.
Wiredworx said,
August 15, 2009 @ 4:43 pm
Great tut! Helps me out loads! Thanks a lot.
Rhys said,
August 30, 2009 @ 3:34 pm
I’ve just completed an adaptation of this to accurately geocode a batch of uk postcodes: http://wheresrhys.co.uk/2009/08/geocoding-in-the-uk/
Timbo said,
September 2, 2009 @ 4:07 pm
Fantastic - thanks, this is way more accurate than the Maps API.
Basil Jose said,
September 18, 2009 @ 1:40 am
Is there any way I can calculate the UK postsode to postcode distance using google maps?
Gareth Moss said,
September 24, 2009 @ 8:07 pm
Hey, great article, but have you noticed the search doesn’t work anymore, I’m guessing google have changed something as my site and yours doesn’t work. :-S
Oh No said,
September 24, 2009 @ 10:39 pm
This stopped working for me recently too!!! Oh no!!!!
ksc1919 said,
September 29, 2009 @ 1:09 am
Thank you for your script.
I got cache.php and geocode.php working fine. Just not clear how/where I add the 2 functions together in step 4 & 5. Appriciate some guidance. Thanks in advance.
Phil Howard said,
September 30, 2009 @ 9:41 am
This script is just what i was looking for.
I’m trying to make a link through to a google map from a dynamic page based on the postcode info for each entry in a mysql database. I’ve tried using the php method you suggested earlier but i’m stuggling to get it to work.
I’ve got the postcode from the url using GET but I don’t know where in the script to put the actual postcode so that the map loads centered on the postcode from the url rather than the GLatLng in the mapLoad function.
ksc1919 said,
October 1, 2009 @ 7:51 pm
Is there a zip file containning sample script I can download to have a look at? thanks
James Hancock said,
October 6, 2009 @ 6:25 pm
Anyone have any suggestions how I could use this to get all of the applicable addresses in a zip? I.e. I want to not have to pay royal mail a fortune for simply getting the town/city from a post code (possible address list would be even better).
Thanks!
Leigh said,
October 8, 2009 @ 12:07 pm
The accuracy of this data returned is now rated a “5″ - The same as that of the Google Maps API
Leigh said,
October 8, 2009 @ 12:37 pm
…but on closer inspection, it definitely still gives more accurate results!?
Payman said,
October 15, 2009 @ 4:20 pm
As part of a research project, I gathered an exhaustive list of all full UK postcodes (just under 2 million records) with their latitude and longitude.
If you’re interested in purchasing it then contact me via payman_labbaf [at] yahoo.com.
Website Development said,
October 27, 2009 @ 1:36 am
nice example
software consultants uk said,
October 27, 2009 @ 1:37 am
Great will use it easily now
Nick Wood said,
October 28, 2009 @ 11:54 am
Google have awful accuracy and DO NOT provide Geocoding. The maps do lack detail adn their premier programme (enterprise is a staggering £7700 and is not great compared to ViaMichelin solutions ) I know this from experience !
This has taken me so long to access and my developers have been flat out for months if finding a provider in the UK who offer Geocoding, reverse geocoding distance calculation, map management, route calculation with excellent maps and mapping technology)and accuracy. Coverage was key in choosing ViaMichelin too as they are a respected brand.
Google lacked support and the Geocoding was very expensive and not great. The other local providers could not stand up and deliver what is needed for me working in the transport industry as good logistics can save you money.
ViaMichelin were so cost effective I saved thousands of what I would ahev paid elsewhere and have a flawless solutions which has allowed me to win many more clients. I would highly recommend VIAMICHELIN API (store locators, Journey planners, directions, toll charges, congestion charge London and Live traffgic info) and the contact there is MARK who came to meet me to discuss my needs, there was no pressure and when I had all the info from 4 companies, It was a no brainer in choosing ViaMichelin Business Mapping and Geolocation for my GIS Geocoding web based webservices platform, It did not take long to developer inhouse and they host it too
Zeeshan Ahmad said,
October 29, 2009 @ 2:34 pm
Hi,
Thanks for this article but one more thing. Can we get the textual address by giving postal code? Is it possible? Just like point.lng(); , how can i get the textual address and the detail like street name etc. If possible then please help me.
Zeeshan Ahmad said,
October 29, 2009 @ 3:40 pm
Hi Paul,
Thanks Dear. I got it.
Fred Smith said,
October 29, 2009 @ 5:08 pm
So is it possible to have a post code search whereby the webiste visitor could find a shop within x number of miles from his house? Without having to go to the Post Office?
Best Free Ads said,
November 2, 2009 @ 4:45 pm
Nice guide bud!
same day courier service said,
November 3, 2009 @ 3:49 pm
I believe the royal mail website has this facility.
Rob said,
November 16, 2009 @ 2:16 pm
I have a problem where I can either set a marker, or I can center the map. When I do both, then only the second one works.
{
usePointFromPostcode(”NW11AA”, placeMarkerAtPoint);
usePointFromPostcode(”NW11AA”, setCenterToPoint);
}
No marker will be shown for the above..
William said,
November 17, 2009 @ 10:42 am
Hi Tom, when I switch to the Map view on your site, all I get is a grey map with my pin in the center - the other views such as Satellite work fine. Can you explain why this happens?
bill said,
November 22, 2009 @ 5:48 am
hi there,
can u do search on city name not on post code? actually i m developing a estate agent’s web site and my requirment is a user can search on city name or on post code if he knows.
waitng….
regards
bill
Daybase said,
December 5, 2009 @ 5:52 pm
I have a map plotting various points from lon lat values on xml file. coordinates are for partial postcodes only eg M34 or SK5 - works great but accuracy so so. xml file also contains postcodes so how would I adapt to geode from the postcode. My code so far
……. GDownloadUrl(”mapdata.xml”, function(data) {
var xml = GXml.parse(data);
var markers = xml.documentElement.getElementsByTagName(”marker”);
for (var i = 0; i < markers.length; i++) {
var name = markers[i].getAttribute(”name”);
var address = markers[i].getAttribute(”address”);
var mcol = markers[i].getAttribute(”mColor”);
var pcode = markers[i].getAttribute(”pCode”);
pcode=pcode.replace(”-”,” “);
so at this point I have my postcode - where do I go from here please?
Rich said,
December 17, 2009 @ 8:52 pm
The end result is brilliant compared to some of the articles out there, one question, it’s probably just me being stupid, but where do you get the includes like gmap.js? Can’t find them anywhere :’(.
Rich said,
December 17, 2009 @ 9:33 pm
My apologies, didn’t see the link :-s.
Steve Smith said,
January 10, 2010 @ 4:45 pm
HI, this looks great - can it be adapted for the Google Earth API?
d jackson said,
January 11, 2010 @ 12:16 am
hi tom
great script - i have it working fine - the only thing i cant get to work is to get the place markers to appear on the first page load - eg: so you dont have to press the Place Marker button
i have tried various things to acheieve this - the most obvious being hardcoding the postcode and adding:
i even tried adding a :
addLoadEvent(usePointFromPostcode(’CA11LE’, placeMarkerAtPoint));
to the gmap.js
but i just cant get the Place Marker to appear on the map when the page initially loads
is it possibly not possible?
many thanks
djax
Margaret said,
January 13, 2010 @ 4:21 pm
Hi wonde r if you can help I need to have a excel spread sheet of Long lat and postcode to suffix level . do you know where I would get this ?
Joel Cass said,
January 15, 2010 @ 12:45 am
Hi Tom,
I guess this was written a couple of years back - it seems things have changed now, the geocoder seems to return the same point data that the local search API does.
E.g. Try entering “”E95AG, UK” into the geocoder getLatLng method and it will return the same point as per the localsearch setSearchCompleteCallback method.
Tom Cox said,
February 4, 2010 @ 6:12 pm
Hi Tom
Probably a daft question, I like how you can fetch the long and lats in display this as an alert. Although is their anyway they can be shown in two seperate textboxs one for lat and one for long?
brian said,
February 6, 2010 @ 6:13 pm
Hi Tom,
Getting an error …
Line: 2
Error: ‘GlocalSearch’ is undefined
I have read through the comments above and thought it might be the .css file so I moved that into my folder but that didn’t work.
Any thoughts as to why the map is not showing?
Thanks
Brian
Andy said,
February 13, 2010 @ 12:31 pm
Hi Tom
I was wondering if you could point me in the right direction..
your code is great but I need to use it in a differnt way. What I’m doing is performing a search for locations in a database that match the area the user enters - so I am extracting a post code for each location from my database then running your code as below several times (once for each maker I want) prior to the body tag being closed.
usePointFromPostcode(’M33 3DA’, placeMarkerAtPoint);
The problem seems to be that the map isn’t displayed and the markers aren’t added - I’m confused…
You can see it here http://sayers.tlatest.co.uk
Any help you can give would be great…
Thanks
Andy
Darren said,
February 17, 2010 @ 3:35 pm
This tutorial is great. I need to take it further I would like the user to select a postcode from a pick up point and a postcode to a destination and then to calculate mileage. Are there any tutorials that can show me how to do this? Thanks
seo india said,
February 24, 2010 @ 7:24 am
really nice information, i incorporate in my programming….thanks
James said,
February 26, 2010 @ 1:10 am
Hi,
Indeed a very great tutorial!
Just wondering if i could get additional help.
Now i want to see the possibility of the lat and long generated to be stored automatically in my database. I know this has to do with defining a function to do the above. But, sorry very new to scripting!
Any help would be greatly appreciated.
Thank you.
James.
Rob Baines said,
February 28, 2010 @ 1:58 am
Great post, exactly what I was looking for. When will the post office ever give up milking their postcode database?
Had it working in minutes. What foxed me was my page will doing postbacks for each click then I spotted all the buttons were type “submit” not “button” , doh!
Pawan said,
February 28, 2010 @ 7:55 am
great post, will try and implement this.
ravindra said,
March 1, 2010 @ 1:55 pm
Very good post.
I want to display multiple locations on the map. How to do this? Please tell me
Regards
ravind