UK postcodes -> co-ordinates : possible purely in php?
Say have a mysql databas开发者_运维百科e with these cols:
| house | postcode | lat | lon |
The postcode's are complete but lat and lon are empty. I want to write/find a script that i can run once to complete the table.
Is this possible purely in php (any tips?) or do i need to use a javascript api and $_POST to a php file?
Without needing any external API
UK Postcode data is now freely available from the Ordnance Survey CodePoint as a downloadable series of CSV files (Feb 2009); but unfortunately the location point is stored using Northing/Eastings rather than Latitude and Longitude.
You'd need to convert the Northings/Eastings to Latitude/Longitude. There's a number of articles about this on the web, e.g.
http://www.deepbluesky.com/blog/-/converting-os-coodinates-into-longitude-latitude_7/
http://mediakey.dk/~cc/convert-northing-and-easting-utm-to-longitude-and-latitude/
but you need to be aware that OS Northings/Eastings are based on the Airy 1830 ellipsoid rather than the WGS84 model used by Google maps (and most GSM systems). Failing to allow for this difference can put you out by anything between 70-120m between Cornwall and East Anglia.
Using PHP, the best solution for this conversion is PHPCoord by Jonathan Stott
There's an XML/JSON API PHP can access via HTTP requests like file_get_contents
or cURL
.
http://code.google.com/apis/maps/documentation/geocoding/
This can be done purely in PHP, relying on some external API that provides you with the lat/lon data.
Generally, web APIs do not care much about the language that's running on their clients. With "JavaScript API" you probably mean a service that returns data in some JavaScript-friendly format, like JSON. However, JSON does not have to be processed by a JavaScript program; PHP programs can parse it just fine.
精彩评论