Python | Get a google map image of specified location using Google Static Maps API

Google Static Maps API lets embed a Google Maps image on the web page without requiring JavaScript or any dynamic page loading. The Google Static Maps API service creates the map based on URL parameters sent through a standard HTTP request and returns the map as an image one can display on the web page. To use this service, one must need an API key, get it from here . Note: One need to create billing account on google then only can use Google APIs. Modules needed :
Below is the implementation :
Python3
# Python program to get a google map # image of specified location using # Google Static Maps API# importing required modulesimport requests# Enter your api key hereapi_key = "_your_api_key_"# url variable store urlurl = "https://maps.googleapis.com/maps/api/staticmap?"# center defines the center of the map,# equidistant from all edges of the map. center = "Dehradun"# zoom defines the zoom# level of the mapzoom = 10# get method of requests module# return response objectr = requests.get(url + "center =" + center + "&zoom =" + str(zoom) + "&size = 400x400&key =" + api_key + "sensor = false")# wb mode is stand for write binary modef = open('address of the file location ', 'wb')# r.content gives content,# in this case gives imagef.write(r.content)# close method of file object# save and close the filef.close() |
Output : 
1 : World 5 : Landmass/continent 10 : City 15 : Streets 20 : Buildings



