How to find the best place to live using the Google Maps API

The problem

Assuming you travel a lot e.g. for your jobs and you want to reduce the time you travel. I wondered in which city you should rent a flat to stay between your trips. In my specific case the only important factor was the travel time. Regarding this, what is the best city? Luckily we can solve this problem with a computer, some programming skills and an internet connection. Some small real-world problems like this are the best way to improve your skills like in a code kata. In Germany, almost every city is connected by rails and tickets are quite cheap. This reduces the cities we have to consider as small towns don’t have a train station. The cities to consider can be picked from a map.

The solution

I wrote the script in python, but a javascript version should work the same way. One input file is a simple list of cities with the concert locations. The other one is a list of cities which are a reasonable to consider. Then the mean travel time with public transport is calculated for each home city. The results are sorted, so you get a ranking. In her case the best city is Cologne. Cologne is quite well connected, so is not that much surprising. You need an API code for the directions API from the Google developer section in order to Google Maps API. A free API key allows up to 2500 request a day, which is more than enough for this task. Using the API is quite easy, but the documentation for the Python API links to the Javascript one. The code for my implementation can be found here.