[go: up one dir, main page]

Build static map URL

Created by: freezed

Use google static maps API without using the API KEY in URL

In some unidentified context (looks like it depends to the used connection) encountering incomprehensible error : Request : https://maps.googleapis.com/maps/api/staticmap?center=48.233309%2C7.367953&markers=48.233309%2C7.367953&size=600x300 Returns : The Google Maps Platform server rejected your request. You must use an API key to authenticate each request to Google Maps Platform APIs. For additional information, please refer to http://g.co/dev/maps-no-account

But if you refresh page the image is served…

Try to build url with :

>>> import urllib.parse
>>> url = 'https://maps.googleapis.com/maps/api/geocode/json'
>>> param = {'address': 'querytextstring', 'region': 'fr', 'country': 'FR'}
>>> urllib.parse.urljoin(url, urllib.parse.urlencode(param))
'https://maps.googleapis.com/maps/api/geocode/address=querytextstring&region=fr&country=FR'