google maps api
I started messing around with the Google Maps API today. Seeing all these “mash-ups” has convinced me that it must not be that hard, and it isn’t!
One thing you quickly discover is that google doesn’t supply you with a built-in way to translate an address into lat/long coordinates – the input they accept in order to plot points on the map.
So, I search for ways to do that, and find an article by John Resig that shows how to use perl to create a proxy to GeoCoder.us. That was exactly what I needed, except I needed it in C#. I bet if I searched harder, I could’ve found something, but it was pretty quick to whip it up myself, so here’s the code to do it:
double geoLat; double geoLong; // Address of Google string address="1600 Amphitheatre Parkway, Mountain View CA 94043"; string url = "http://rpc.geocoder.us/service/rest?address="; XmlTextReader reader = new XmlTextReader(url + address); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(reader); XmlNodeList gPoints = xmlDoc.GetElementsByTagName("geo:Point"); geoLat = Double.Parse(gPoints[0]["geo:lat"].InnerText); geoLong = Double.Parse(gPoints[0]["geo:long"].InnerText);