I’m working on this GeoRSS extension for ArcGIS and needed some data to play around with so I had a search around to find speed camera locations in Auckland, NZ and tracked down some data on-line (a list of addresses). Once I had the list of addresses I needed to geocode them and chose to do this via the Google Geocoding API.
I needed a quick way to geocode a list of addresses rather than do each address individually. I also wanted to ensure that I could easily do this again, here’s some sample code:
1. Send the request to google and stream the response back into a string variable
WebRequest request = WebRequest.Create("http://maps.google.com/maps/geo?q=" + address + "&output=xml&key=" + googleID); // If required by the server, set the credentials. request.Credentials = CredentialCache.DefaultCredentials; // Get the response. HttpWebResponse response = (HttpWebResponse)request.GetResponse(); // Get the stream containing content returned by the server. Stream dataStream = response.GetResponseStream(); // Open the stream using a StreamReader for easy access. StreamReader reader = new StreamReader(dataStream); // Read the content. string responseFromServer = reader.ReadToEnd();
2. Create an XML document using the response, add in the necessary namespaces to enable xpath querying of the document and check the status of the response
//create an xml doc XmlDocument doc = new XmlDocument(); doc.LoadXml(responseFromServer); //Add a Namespace Manager XmlNamespaceManager xmlNsM = new XmlNamespaceManager(doc.NameTable); xmlNsM.AddNamespace("AddressDetails", "urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"); xmlNsM.AddNamespace("kml", "http://earth.google.com/kml/2.0"); XmlNode xmlNode = doc.SelectSingleNode("//kml:Status", xmlNsM); status = xmlNode.InnerText;
3. Parse the results
//parse xml response from google if (status == "200geocode"){ //do something with the geocoded results }else{ //handle unsuccessful results }
I wrapped up the above in a simple app which allows me to enter my API key and the location of a address csv file.

I managed to get my speed camera data geocoded – next on the list was to convert this to GeoRSS. A while ago i hacked an exporter together for ArcGIS – the predecessor to the extension mentioned above – it does what I needed for this job, so I loaded my data into ArcGIS as an event theme, created a shapefile from it then used the exporter to export a simple and GML version of the speed camera data. Perfect – I also exported a GeoRSS of primary schools as I thought it might be interesting to look at the locations of the speed cameras in relation to the location of schools.
Once I had the feeds all I needed to do was visualise these – previously I’ve worked with the Google API to do this, but recently I’ve been playing with OpenLayers so thought i’d use this especially as I could use the Google data and create different styles for each feed layer – here is the result

Considering the recent campaign here in New Zealand about speeding near schools it suprises me how few speed cameras are near to schools (and this map only shows primary schools) .
Sweet. I bet the locations are determined by revenue potential not safety.
Interesting,
it’s better than google map for sure
Thanks for writing, most people don’t bother.