Search code examples
pythongoogle-mapsgoogle-maps-static-api

Google static API large zoomed map


Hi,

For a project i'm working on I need a lot of maps from different places around the world zoomed to building level. I tried to use Google static map API and python to achieve that. I planned to divide the area I need and take multiple pictures in a for loop. But i don't know how to take the exact zone next to the previous one.

Here is my code:

import requests

apiKey = "YOUR_API_KEY"
url = "https://maps.googleapis.com/maps/api/staticmap?"
#center peut être égal soit au nom d'une ville, d'un pays, continent ou 
{latitude,longitude}
center = "Binche"
zoom = 13

completeUrl = url + "center=" + center + "&zoom=" + str(zoom) + "&size=640x640&key=" + 
apiKey + "&style=feature:all|element:labels|visibility:off"

r = requests.get(completeUrl)

with open(center + " Zoom " + str(zoom) + ".png", 'wb') as file:
    file.write(r.content)

And here is my result:

enter image description here

Everything is good... Except i need a way bigger area. And to have an area this big I had to put the zoom value to 13 (i would like 20).

So, How could i have multiple pictures (or a single one) of a zone (~100Km). And another question would it cost a lot with this API ? If you think it's not possible and you have another idea feel free to write it :).

Thanks for your time !


Solution

  • I'm assuming that what you want to know is these:

    1. How to load a static map of a large area

    2. How much would it cost

    Answer #1

    You should check out this link to learn more about zoom levels.

    Larger zoom levels does not mean a bigger area, in fact, it's the other way around.

    Maps on Google Maps have an integer 'zoom level' which defines the resolution of the current view. Zoom levels between 0 (the lowest zoom level, in which the entire world can be seen on one map) and 21+ (down to streets and individual buildings) are possible within the default roadmap view....

    The following list shows the approximate level of detail you can expect to see at each zoom level:
    1: World
    5: Landmass/continent
    10: City
    15: Streets
    20: Buildings

    So what you should do is to change your zoom value lower.

    Answer #2

    You should check out this link

    The Maps Static API uses a pay-as-you-go pricing model. The Google Maps Platform APIs and SDKs are billed by SKU. Usage is tracked for each SKU, and any API or SDK may have more than one product SKU. Cost is calculated by SKU usage × Price per each use.

    The "per each use" here means per map LOAD. This means that regardless of the zoom levels that you use, you will only be billed per LOAD of the Static Maps API. That means if you load multiple static maps, you will be billed per map that you loaded. And it costs around 0.002 USD per LOAD if your load amount per month does not exceed 100,000. You can check the pricing table on the link I provided for more information.

    Hope this helps.