===============
Google Maps API
===============

``Google Maps`` has a *free* api that can be used to calculate distance matrixes as well as show point on a map. 
In order to use this API you will need to request an API key from the `google cloud console <https://cloud.google.com/>`_.

This API can be used at a cost for each request, but Google gives ~200 dollars worth of request at the start of every month. 

Using the Google API
####################

For a quick test to see if it was possible to geolocate each house and calculate the distance. For this a simple python script was used.

.. code-block:: python

    origin_locations = {
    "nfi_location" : (52.044867266861466, 4.3585175985355225),
    "hoogstraat_location" : (52.08725689123654, 5.147180442716177),
    "bakkersdijk_location" : (51.85802695253161, 4.482033956202426),
    "korhoen_location" : (52.5219455005375, 5.732514040876346),
    "harde_location" : (52.41650138296019, 5.870995170999243)
    }

    def get_distances(out_dict, destination_location):
        for key in origin_locations:
            distance = gmaps.distance_matrix(origin_locations[key], destination_location, mode = 'driving')
            out_dict[key] = distance['rows'][0]['elements'][0]

We can do about 40.000 request for free each month. With about 1200 houses and 6 requests per house that would mean up to 7000 requests. 
That is enough to build a quick PoC to see if this method would work.

.. image:: images/poc_houses_on_maps.png

This works and a lot of houses are shown on google maps with markers.

Google Ban
##########
Another result of this action was a Ban from google. 
The reason for this was that I did not read the terms of use. 
You are allowed to do 40K requests for free every month, just not several thousand in a few minutes. Oops.

.. image:: images/ban_google.png

Because we want to do more than 40k requests and dont want to pay for these requests, the project was switched to **O**\pen **S**\treet **M**\ap(OSM)