Real World Computing
Bowled a Googly
In the meantime, there are plenty of companies that will license you some of the data for varying amounts of money depending on your intended usage. QAS (www.qas.co.uk) is possibly the best known of these providers - I've used its products in the past and been impressed with the level of support, but for a lot of applications the price is still prohibitive.
Back on the map
But enough of this, back to my project. If you want to see the problem for yourself then enter your postcode followed by ",uk" into the textbox on Mike William's page - which uses the Google API - at http://econym.googlepages.com/example_geo.htm, then go to http://maps.google.com and enter the same postcode to see the correct location. Quite a gap, no?
These limitations show how essential it is to undertake thorough testing if you propose to use third-party services and APIs for your line of business processes. If maps and pushpins aren't totally accurate on your Facebook page, it's probably no big deal, but if you're running a business site that shows event venues you'd have some pretty irate customers on your hands. I always advise my clients to think long and hard before deciding to use any free third-party service on their production website. Ask yourself: what would be the implications to my business if that service went down or didn't perform as expected?
As I eventually wanted to put a hundred or so pushpins on my maps, doing postcode look-ups for each one wasn't going to be viable, so I decided to first add all the latitudes and longitudes to the address database by buying the data in. With the address list now prepared, the next choice was whether to use Google Maps or Virtual Earth to display them, and I decided in favour of Google Maps after a very interesting phone call to Duncan Garratt, one of the foremost UK experts on mapping technology. He suggested going with Google Maps, as in his experience it seemed to work through firewalls and various security setups better than Microsoft's offering. It was also he who suggested Mike William's site for some sample code. Mike's examples illustrate a wide variety of what you can do with Google Maps, and all he asks is that if you find them helpful, hit the PayPal button and donate something to his church, Blackpool Community Church, which is a nice touch. I duly sent him something - after making sure his code worked, of course!
Putting one pushpin on a website is fairly easy, but putting in several requires more effort. I decided to hold the data in an XML file on the server (without the postcode, just the venue name and its latitude and longitude). I then needed to read this file, extract the data and pass that to the Google API to build my map. I shan't show all the code here because space is limited and there's a fair bit of it, but I'll just run you past the basic concepts. First, you need to create a map object:
var map = new GMap2(document.getElementById("map"));
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
We'd advise specifying the centre point of the map; otherwise, it will centre around the US:
map.setCenter(new GLatLng( 52.61852061,-1.10331493), 7);
You now need to create a function that will create a marker (pushpin) and this will be called several times, depending on the number of records in your data set:
