There's a lot of UK Drupal users, right?
I'm really interested in extending the system to support locations in the UK.
There's a freely distributable data source for UK postal_code/lat/lon data in the UK: http://www.jibble.org/ukpostcodes/
The drawback with this dataset however, is that the data is not complete and does not pair postal codes to city names.
If possible, perhaps the file can include instructions on how to use data purchased from the Royal Mail Service if the user wants complete data:
http://www.royalmail.com/portal/rm/jump2?catId=400120&mediaId=400084
Of course, implementation would also mean (though not require) adding functions for theming UK addresses, providing deep links (http://www.mapquest.co.uk is a good place to start), and so on.
-Ankur
| Comment | File | Size | Author |
|---|---|---|---|
| #47 | postcodeanywhere.js_.txt | 9.36 KB | kenorb |
| #42 | zipcodes.uk_.mysql_.txt | 204.53 KB | andrew.lansdowne |
| #41 | Uk-Postcodes-Towns.txt | 123.54 KB | knight42 |
| #27 | location.uk_1.inc | 8.47 KB | timcollins10c |
| #17 | uk_geocode.csv | 93.08 KB | martinb9999 |
Comments
Comment #1
Dublin Drupaller commentedgood ideas..
two quick points:
a. pairing postcodes with city/town names..in the UK. that would be useful and I would imagine it would be implemented in a simple flat comma seperated text file or an include file. is there copyright issues on the royal mail list? am guessing there is...so perhaps a bit of googling will track down (pun intended) a source that you could use.
b. until seeing that mapquest thing...I was playing with inserting a direct link to multimap.com with the Users post code in the link...which was great as it also offers a camera shot of the street as well...
the only drawback was the multimap.com site drives my anti-spybot software mental as it tries to install all sorts of weird cookies or something, so I stopped using it. that mapquest thing looks good, even if it doesn't have the camera thing.
if it's of use...I posted how I automatically inserted a link to a street map in a users profile here:
http://drupal.org/node/14466#comment-26095
Dub
Comment #2
geodaniel commentedI have updated the location.uk.inc file to link to Google Maps and Multimap.
The links use the geographic lat/lon co-ordinates if they are available, or, if not, postcodes, and if there is no postcode then street name and city.
I hadn't realised there was a free distribution of UK postal sectors at jibble (though the file doesn't seem to be there at present). I wonder if this could perhaps be tied into the postal area or postal district names from Wikipedia to allow lookup from postcode to town/city and also provide a lat/lon whilst it's at it? Are there any licencing issues with doing that?
Comment #3
martinb9999 commentedQuick question - do you absolutely need to have a local copy of the PAF?
Why not screenscrape Google Maps which handily returns the lat/long pair in its page (although not via the API).
Quick and dirty example, lifted and PHP'd from this Perl example:
http://morland.theoretic.org/archives/2005/04/15/free_geocoding_thanks_t...
http://colonsay/~martin/geocode/gmap.php
Code at
http://colonsay/~martin/geocode/gmap.txt
Comment #4
martinb9999 commentedPresumably also, one doesn't need a complete geocoded PAF stored locally in the zipcodes table. One only needs entries for where you've got nodes as a local cache.
So perhaps the answer for where no complete db is freely available:
1) On node creation and Google-supported location is provided, geocode it then:
a) If it's not already in the zipcodes table, put it there
b) else if it is and it's different, assume a geocode update (it happens - our postcode is currently geocoded wrongly by Google, but correctly as per latest version of PAF) and update the table
2) On location search:
a) If it's in the zipcodes table, use that
b) If it's not, Geocode from Google, use the result and store it in zipcodes
This is tuned for reads: making the assumption that searches will be more frequent than node adds, and that the performance hit of screenscraping Google isn't significant at node creation.
Of course, once the data is in zipcodes table, it's business as usual.
Comment #5
martinb9999 commentedHmm screenscraping Google Maps may be against their ToU. Yahoo! provide a very cool Geocode API, but, you guessed it, it's North America only.
Comment #6
geodaniel commentedIt's a good idea Martin, but as you point out, it may breach their Terms of Use. Sadly I think that would almost certainly be the case.
For now I reckon postal sectors (like M14) is the way to go as they would provide a set of locations to a few miles resolution or so I think (similar to a US 5 digit zipcode?) - though I'd like to see that dataset to see their distribution.
Comment #7
JohnG-1 commentedideally PAF files would be centralised (not local) to make maintenance easier.
if this is pie in the sky, my apologies, but:
what about clubbing together to buy a licenced PAF from the Royal Mail and storing it on a Drupal server ... ?
Comment #8
xand commentedI sincerely doubt you could buy that for any reasonable price. I don't think Royalmail is quite that silly.
Also, if the information is on wikipedia, it is almost definitely free to use/download/etc. Look at the copyright information at the bottom of the page.
Comment #9
JohnG-1 commentedRoyalmail data licences seem to be way overpriced, and simply not that useful.
All I can find on wiki is this http://en.wikipedia.org/wiki/List_of_postal_areas_in_the_United_Kingdom which appears to be very similar to the 'province list' dankarran has used in the patch file. It only covers the first 2 letters of the postcode, so does not enable a very high level of detail.
The jibble source (http://www.jibble.org/ukpostcodes/) covers the first 2 letters and first 2 numbers (eg AB12) which should narrow down locations to within a few miles (I guess). Also includes Long/Lat co-ordinates which are very useful. (not come across the x/y co-ords in metres before ...?)
It should be very easy to map the wiki list (approx 120 city names) onto the jibble file.
I'll do it manually if someone can tell me how! I'm no programmer so I don't understand what format the inc file data needs to take.
Comment #10
JohnG-1 commentedfound a UK postcode file via http://www.brainstorm.co.uk/uk_post_code_search.htm
it seems freely availble : "available for free download" ! though probably best to ask ...
File is 1800kb text format (the smaller files contain less towns (rows) but same details (3 columns)
sadly they do not include lon/lat data.
It looks like the records are also incomplete (my home town is not listed).
snip eg: (drupal codefilter collapses the spaces that separate columns)
there is also a telephone STD area code file at http://www.brainstorm.co.uk/stdcodes.csv
my hometown appears on this one ... :)
are these of any use?
Comment #11
martinb9999 commentedResponses to a few things in one:
Can we not just go Pinchot on this and JFDI? Throw the Brainstorm list (sorted by unique postcode district) at Google once and just then use that[1]?
Taking advantage of the 'probably against' ToU we should be able to apologise afterwards without too much in the way of consequences, unless we're dumb enough to do a jibble and make the compiled list separately (and very visibly) downloadable. RoyalMail are probably not going to be as upset about district-level data as the real money is at postcode unit level for geodem etc.
[1] Caveat updates to the PAF, so prolly needs to be an annual event, but by next year, the Yahoo! GeoCode API may cover the UK. Not so much of a worry at district level anyway.
Incidentally, I have the base 'geocode from postcode and insert into zipcodes table for future user' function working... see attached
Comment #12
martinb9999 commentedMinor niggle with this approach - postcode district data doesn't always return data for 3 char data elements (AB1 for example). Ho hum - much of it is useful, though. I may do sample full postcodes for those districts that failed and re-run.
Comment #13
martinb9999 commentedIf you do it that way, here's the problematic districts (see attachment)
Comment #14
martinb9999 commentedBlimey, I'm a busy bee today and should have concatenated these replies.
Anyway, the fun about trying to link town names to postcodes is that there isn't a simple correlation - some towns are split between postcode districts, and all have multiple towns/villages/hamlets per district. Same story for counties. And postcode areas are *far* too unspecific to be useful (as an exercise, take a look at the coverage of PA, or IV).
So if you're using the postcode as a primary key, you're not getting enough at the district level to be absolutely sure of the town and county. As http://www.statistics.gov.uk/geography/postal_geog.asp points out, we can go to sector level (and have 11598 rows in the table), but there isn't a comprehensive list available (unless anyone's got it to hand). Even the Brainstorm district list is short - the above URL claims 3064 districts, and Brainstorm only provides 2531.
To provide an accurate, up to date table, you're either going to have to license PAF, or do an on-demand query to an online service. If you want it *free*(beer), you're screenscraping until such time as Yahoo! brings its API to the UK.
Comment #15
geodaniel commentedMartin,
Are you saying then that if we were to geocode those missing districts then that would give us a complete dataset? I got lost somewhere in the thread of which files you were comparing. I don't have any issues getting the lat/lon data for just a small set of distrcts but I don't think we should be scraping the sites for complete postcode geocoding...
You're right when you say about tieing postal districts to names, that's not a simple task, and perhaps unnecessary - just a nicity? I realised that the other night when trying to get a dataset of Isle of Man (IM) postal districts together. I'll be geocoding IM1-IM9 soon, and maybe even IMx x as that data is indirectly available (perhaps with a little of my local knowledge) through the post office website in the form of a map showing where the areas are.
Comment #16
geodaniel commentedBy the way, I found that list of geocoded postal sectors that used to be on jibble.org, and thought I'd put it here for safekeeping and incase any of you guys don't have it.
Interestingly, Google doesn't return locations for AB1 (or any other, seemingly) of those other districts that appear to be missing, though they do return results that have AB1 as part of the content on their pages. I wonder if they are using this same non-complete dataset of geocoded postal sectors?
Comment #17
martinb9999 commentedDan
If we geocoded those missing areas we'd have a *more* complete set. But ONS suggests that there are 3064 Districts (AB1), whereas the Brainstorm dataset - like Jibble - only has 2600 or so. I've attached my dataset, which has counties (subject to the caveat that some districts cross county borders). Where the lat/long is 23.875/57.630033, this means "unavailable from Google"
You're right though, Google doesn't appear to have data for AB1 at *all*. All the postcode searches I try for there fail (eg Aberdeen Dyce airport's postcode: AB1 7DU).
You're also right in that scraping the complete postcode dataset (1.78million elements) and including it in the module download is probably both unnecessary, unfair, and wouldn't add enough benefit for the size of download required. I still think that an on-demand basis for postcode units is probably best, but with the district level data as backup. This means we don't have to distribute detailed data *at all* and each installation's dataset is tuned for their users.
So, where does this leave us? Perhaps with accepting, geocoding and storing full postcodes for nodes, but on performing Nearest X searches, cutting the data entered down to district level (which is mostly already geocoded in the db) for performance reasons. So a search would effectively be:
which returns nodes with geocoded full postcodes in the vicinity.
Comment #18
dan_aka_jack commentedHi,
I too am very eager to use Drupal to do proximity searches and to link to Google maps. Is there any news regarding this project?
Many thanks,
Jack
Comment #19
wackimonki commentedI am not sure if this is what you're looking for, but a number of companies offer postcode geocoding through Web Service. iShareMaps does this. It does cost to integrate it, though cheap. It is free to use on their website. See www.geocode.isharemaps.com.
Comment #20
owen barton commentedHas anyone seen the free collaborative geocoder.us style http://www.freethepostcode.org/
It has both downloadable data files and geocoder lookup.
It's only got ~700 entries right now but is definately worth keeping an eye on!
As far as paid lookup services go I also found http://www.postcodeanywhere.co.uk/, which has a more flexible pricing model than http://www.geocode.isharemaps.com/ - as well as a the standard fee (which is also cheaper £160/year for street level) you can buy 'credits', 1 per geo lookup and £50 for 1,000 credits. This is more useful for smaller sites!
Comment #21
buddaHere's a much nicer way of getting log/lat from a UK postcode:
http://www.streetmap.co.uk/streetmap.dll?GridConvert?name=EX331JZ&type=P...
Screen scrape and store on node creation. Seems to be always up to date too (for my test postcodes).
Comment #22
buddaThat URL in full:
Comment #23
geodaniel commentedI'm still interested in this but don't have much time available to work on it at the moment.
Having been working a lot on the OpenStreetMap project and recently a little on the Free The Postcode project, I'm very reluctant to do screen scraping of postcodes. In my eyes, the data is either going to have to come from a free source (eg Free The Postcode) or a source that has proper licencing arrangements in place. Perhaps this will be Google at some point, but the UK is one of the countries missed out of their geocoding API.
With Free The Postcode, I'd say around 50% of postal areas have coverage at present, and there's still a long way to go before all of the districts [zz9] contain the location of at least one postcode. But once the project grows some more, it would be good to tie into the geocoding facilities over there to be able to pull in approximate locations based on postcodes being submitted to Drupal.
Comment #24
buddaLooking at Free The Postcode project it is going to take a bloody long time to cover everything well enough to use the data in a functioning site.
Maybe an established Drupal site could be used to collect the postcode data as its requested (via a screen scrape) and then contribute the values back to somewhere.
How is anybody going to know if the long/lat is borrowed from somewhere else? :-S
Comment #25
stanbroughl commentedHave a look at www.geonames.org they got a great global database going and open source webservices available - do you think that could be used?
Comment #26
ankur commentedI know that the Google Maps API recently added a free geocoding webservice to it list of public functions: http://googlemapsapi.blogspot.com/2006/06/geocoding-at-last.html
If it does UK addresses, then I'd suggest someone look into adding a geocoding option for UK/Google maps. I recently updated location.module, location.inc, and location.us.inc to allow for an interface that give the admin the ability to select a geocoding option on a country-by-country/service-by-service basis. The only one I've implemented, however, is the Yahoo! Maps geocoding. If you want to implement something similar for the UK that uses google (of course, someone will have to verify that the service geocodes UK addresses) let me refer you to the following functions:
supported/location.us.inc
---
function location_geocode_us_providers
function location_geocode_us_yahoo_settings
function location_geocode_us_yahoo
location.inc
---
function location_latlon_exact
In the absence of documentation right now, these four functions should give enough information to implement something that does the same thing for UK addresses using google instead.
Comment #27
timcollins10c commentedI am not 100% familiar with how this works, but from you comments I thought I would have a go, not successful but am I going down the right direction (see attached file)? Has anyone else had any success with getting this working for the UK yet?
On a related note see http://drupal.org/node/79015, I am also finding that the Province is no longer saving.
Comment #28
timcollins10c commentedSorry, think I missed a point earlier on, after trying to return data from goodle uk geocoding, I realised that is not available for the UK, probably said that earlier in this stream. Does anyone know if it will be at some point?
Comment #29
Tobias Maier commentedregarding to your new varable "location_geocode_uk_google_apikey":
the Gmap Module already asks for this api key: why not reuse it and its variable?
http://drupal.org/project/gmap
the variable is called "googlemap_api_key"
I suggest to replace yours with the one of the gmap.module
Comment #30
obslogic@groups.drupal.org commentedI've done some quick work at http://drupal.org/node/75459 to create a location.uk.inc file that uses the Geonames.org webservice to fetch rough locations for UK addresses... (download via that link)
I think geonames are using the Jibble postcode database (or similar), so search returns a location based on the first part of the postcode only. When a postcode isn't provided, the search uses the city name to location a latitude and longitude.
It's all a bit messy at the moment (it doesn't advertise itself as a geocoder properly etc..) but may do the job for people wanting quick rough UK geocoding...
I'm hoping to do some more work on it soon....
Comment #31
firefishy commentedpublic domain UK Postcode -> lat: http://www.npemap.org.uk/data/outward1list
Comment #32
csc4 commentedIs this still going?
I'm struggling with the UK province list - the muddling of counties and cities, the odd abbreviations (and their use in $location), then there's the issue of Wales, Scotland and the Channel Islands... and Ireland vs Repulbic of Ireland
Can't really believe I'm the only one!! Is there a more 'UK' friendly location.uk.inc you're all using or is there an even better way?
Comment #33
ankur commentedWell, I originally made the mistake of thinking everyone in the UK uses counties. Apparently this doesn't seem to be the case.
I did a little googling and discovered that England, Scotland, and Wales are seperate kingdoms or countries (or whatever) and that Northern Ireland is a "province" and that within each of these, some like to use "counties", some like to use "regions", and some like to use "districts". You brits need to make up your mind!
Anyway, I would prefer that we do it the way that the postoffice would expect; and from what I understand, you only need a city/town name and a postcode (what we call zip code and what some might call postal code; you brits are funny). So, in short, I think we should eliminate that field altogether for UK addresses altogether by making the function location_province_list_uk() return an empty array.
Anyone else with thoughts on this?
I'm thinking that we can make it so that if someone does have some kind of need for a "county" in their address, they can implement it as a seperate add-on field similar to the way location_phone.module adds on an extra field to the location form (see http://cvs.drupal.org/viewcvs/drupal/contributions/modules/location/cont... )
Comment #34
csc4 commentedFunny indeed! and thanks for helping! I'm very grateful.
I'm kind of surprised I'm the first Brit to have raised this! Surely there are other Birtish location users out there?
I like location - it seems a very 'Drupal' way to do addresses (though for 'true' Drupalness reusable venues seem like a must (to me!)) but the user interface (not being able to select country, then province so the province list isn't so overwhelming) and problems I'm having categorising addresses so I can search on them are such that I'm wondering if I'll have to go to taxonomy? as there seems no relationship ability between countries and provinces (and I think ideally I'd even like one more layer province - district)
Anywhere which isn't 'true' London (or Manchester) uses Counties and they're fiercely proud of them - the Royal Mail has 'had a go' at several counties (especially Middlesex) but the inhabitants are pretty resistant to losing their counties!! 'Official' information at (also referenced by though as I say counties are really quite important - and I need to be able to produce county lists of location data.
I think you might like !! though even he seems to do down counties!
For example -
Grand Harbour Hotel, West Quay Road, Southampton, Hampshire, SO15 1AG - is a pretty typical address and this is how they use it themselves (and Hampshire is abbreviated to HANTS not HAM!!)
London's a law unto itself - I've never seen letters addressed to 'HMF' => "Hammersmith and Fulham" (and I lived in London for over 20 years!!) - they're 'London Boroughs' and it would be quite nice to have them optionally in the address but HMF would mean nothing to anyone - they just don't abbreviate - so I don't know what to do about them (but if the pretty name was displayed by default in $location it wouldn't really matter what abbreviation was in the database).
Counties are a big deal - think States! - and the smaller the county the prouder - many have their own flags! and you fiddle with their borders at your peril, ignoring them is a capital crime! It is true that a letter will get to a town and a postcode but trying to do regional event listings with just that is very hard indeed!
For example, someone in Totnes, Devon would expect to see
Location currently produces
DEV means nothing to anyone over here!! and it gets even worse for Bedfordshire etc. - Bedfordshire would normally be BEDS or Bedfordshire - not BDF. I think I can sort the abbreviation issue by working through them and putting 'better' abbreviations in but it would still be nice to be able to have the full county.
City duplication is another problem - I wouldn't want an address to say Plymouth, Plymouth! It should be Pymouth, DEVON. I need them to put the city in the city! otherwise I can't search (again if they went in the same optional field as London boroughs (as a sort of 'near Plymouth') that would be ok). Don't large states have 'neighbourhoods' or 'districts' people would be interested in? like say all events
in Queens in New York?
Wales, Scotland and Northern Ireland like to see themselves in addresses - this makes life very tricky - especially as Province has baggage - Wales is a Province but Scotland isn't.
They'd expect their addresses to look like
ideally from outside Scotland they'd also like to see
Similarly
Again - it's very important to be able to produce a list of Scottish events - I can't do that if there's no way of searching on them!
Then there are the Channel Islands - Jersey, Guernsey etc (and the Isle of Man and Isle of Wight which would expect to see themselves in an address!).
Comment #35
JohnG-1 commentedah ... a nation built on compromise :P ... and the Republic of Ireland (AKA Eire) doesn't have any postcodes at all ... ;)
Comment #36
csc4 commentedIs there any chance any of this could make it into the proper releases?
The patches seem to add geocoding support to some extent - if the Counties/Province/Kingdom issues could be resolved it would make locations useable for UK users at last!
Comment #37
TimDavies commentedGoogle are now offering UK Geocoding - so I've created a location.uk.inc at http://drupal.org/node/158101 which can use this.
(Doesn't take into account any of the discussions above...)
Tim
Comment #38
rich86 commentedHi, sorry to revive an old thread but I'm a bit confused - has support for UK postcodes been implemented within the locate module?
Comment #39
ankur commentedWe have geocoding via the google web-service. We don't have a data dump that pairs postcodes with lat/lon coordinates. Free data is hard to come by though things may've changed since I last checked. In any case, you're better off using the geocoding.
-Ankur
Comment #40
rich86 commentedOk, so I can use geocoding on my site via the google API? How do I go about using that?
Comment #41
knight42 commentedHi
Im wondering if anyone has any more info on how this is going. I have a list of UK post codes with coordinates, but its set in a different format to the US sql list that is included with the location module.
So im wondering, If I go through the list and reformat it so its the same, then upload it, will it work as a database for UK post codes?
Comment #42
andrew.lansdowne commentedYes, in order to enable Drupal to search for nodes by proximity to a user-entered part-postcode (up to 4 chars) you just need to create a SQL file based on the free postcode data listed above, import it into zipcodes database, then modify location.uk.inc so that it contains the two functions "location_latlon_rough_uk" and "location_get_postalcode_data_uk". Copy them from location.us.inc (dont forget to rename the functions) and alter so that it does not mess with the postcode (look for substr, str_par). As my requirements don't require city or province names I have not put those into the SQL, these could be easily added for a more complete package.
I am attaching the sql script which inserts the FREELY available postcode to lat/long data into Drupal. For reference here are my versions of the functions:
Comment #43
knight42 commentedHi Andrew
Thanks for all that. Ive installed it all, and it works, albeit a little randomly. Im having a few problems with getting the right results in views and wondered if you could help, dunno if this is something I have done wrong or maybe a small bug.
For instance I tag nodes with a Postcode, so there all ready. I have one marked with the postcode TN24
But when I search and put tn24 (5 miles radius) in the search, nothing is returned. It cant find local things! Its returning other postcodes just fine, again some of them are a little out in their distance.
How precise should this be? any ideas?
Thanks
Comment #44
bdragon commentedMarking master.
Changing component to Data update.
Comment #45
brmassa commentedGuys,
commited on HEAD. Soon on Location 3.0
regards,
massa
Comment #46
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.
Comment #47
kenorb commentedIf anybody using postcodeanywhere to receive Postcodes, here is javascript file which can be easily implemented for specified form.
Please change your licence code and id to the postcode fields inside of the file.
Comment #48
kenorb commentedCreated new project if any interested:
http://drupal.org/project/postcodeanywhere
which integrate postcodeanywhere service