XQuery/Google Geocoding

Motivation
You have one or more geographic names and you want to create a map of these locations.

Method
We will use a Google RESTful web service to return geographical data from a list of place names. Google provides an HTTP-based Geocoding service. This requires registration of a site for a API key and there are limitations on the usage of this API. Results can be returned in XML or JSON.

Querying Google's API
The following script takes a location and returns the xml from the service:

Examples
Single City Examples:


 * Minneapolis - example using a single city with no country
 * Bristol,UK - example using a city and country

Multiple matches may be returned:
 * Bristol
 * or a false positive: Santa's House

In the UK, this service will geocode postcodes:
 * Bristol Hackspace

Response as KML
The XML response can be reformated as a KML file. Note the addition of the relevant media-type for KML.

If you have GoogleEarth, this should load an overlay showing multiple Bristol locations: Bristol KML

GoogleMap
A simple way to view the generated kml is to use GoogleMaps. This script simply constructs the relevant URL to use the script above and then redirects to that URL:

Sadly this approach no longer works with GoogleMap - see support lost  Bristol

An alternative approach is to use GoogleMap's JavaScript API. Note that to embed JavaScript requires doubling { so it is generally easier to put the Javascript in a separate file. This approach makes use of any existing kml overlay and is simpler, but more restricted than implementing the map using the JavaScript API

Examples
* Bristol * London

[Setting the zoom level doesn't seem to work]

Data to overlay
Often the locations are defined in a data file. The following script reads a local file of (a sample of ) whisky distilleries and creates a KML overlay.

Whisky overlay

and a modified version of the JavaScript can use the output to create a Whisky map