One quite popular post on this site is the Geocoding for Excel post. In common with lots of the code snippets here, the code was stripped down to the bare minimum to make it understandable and functional.

I happened to be debugging a recent tool (the EPW weather file finder) and thought that it might be an idea to upload the finished version including features like results caching, error handling, URL encoding, and avoidance of localisation problems from the use of commas as decimal separators.

As before it returns latitude and longitude, but it now has three additional options for the return values and one to force the function to requery Google, for example if you think the value it has returned is incorrect.

=G_LATLNG("Trafalgar Square") returns 51.5073346,-0.1276831
=G_LATLNG("Trafalgar Square",1) also returns 51.5073346,-0.1276831
=G_LATLNG("Trafalgar Square",2) returns 51.5073346
=G_LATLNG("Trafalgar Square",3) returns -0.1276831
=G_LATLNG("Trafalgar Square",4) returns Trafalgar Square, City of Westminster, London, UK

To force the function to requery you need to set the Requery option to True like so: =G_LATLNG("Trafalgar Square",,True) (note the two commas – you can also still use the number codes as the second parameter to return latitude, longitude or address).

There’s quite a lot of code in this function, but it’s well commented so should be reasonably easy to follow.

This depends on the following functions:

Jamie Bull | jamiebull1@gmail.com

Related Posts

WiGLE is a popular platform which can be used for finding the location of a device using the names of WiFi networks in its vicinity. I’ve written about this before, and wrote some Python code to interact with their API. This API has since been retired and replaced with a new one, as of December […]

Just a quick post to point out a couple of really useful tools. The first is a web-based tool for finding weather files for a location of interest. It’s similar to the Excel EPW finder tool we created a few years back, but much more modern looking. It is however missing a few of the […]

Eppy is a really useful library which I’ve written about several times, since before I really had anything to offer in terms of contributing code. Over the past year or so though, I’ve started to contribute back some of the changes and additions I’ve made while using eppy on academic and commercial projects. This post […]

Leave a Reply

Your email address will not be published. Required fields are marked *