import urllib.parse import urllib.request from io import StringIO import PIL from PIL import Image from math import log, exp, tan, atan, pi, ceil import io import math from urllib.request import Request zoom = 17 # be careful not to get too many images! # Set some important parameters scale = 1 maxsize = 640 # calculate pixel dimensions of each small image fieldminlat=22.539862 fieldminlong=72.966847 fieldmaxlat=22.537365 fieldmaxlong=72.970709 bottom = 120 upperleft = str(fieldminlat)+','+str(fieldmaxlong) lowerright= str(fieldmaxlat)+','+str(fieldminlong) print(upperleft) print(lowerright) centerlat = (fieldminlat+fieldmaxlat)/2 centerlong = (fieldminlong+fieldmaxlong)/2 position = str(centerlat)+','+str(centerlong) width= 100 height= 100 print('width'+str(width)+'height'+str(height)) api_key = "AIzaSyBO5HDklsIeFNmKMGDLoImadHH57eQ4c2k" api_key = "AIzaSyDnM_35WfYwhJmTSPxyyiMIcYte65mPitc" urlparams = urllib.parse.urlencode({'center': position, 'zoom': str(zoom), 'size': '600x600', 'maptype': 'satellite', 'sensor': 'false', 'scale': scale}) url = Request('https://maps.googleapis.com/maps/api/staticmap?' + urlparams+'&key=' + api_key, headers={'User-Agent': 'Mozilla/5.0'}) print(url) f=urllib.request.urlopen(url) image_file = io.BytesIO(f.read()) im=Image.open(image_file) width1,height1 = im.size #new_height = height1-25 #width1 = width1-25 #im =im.crop((0,0,width1,new_height)) im = im.resize((width,height)) img_name = 'sample_static_map.png' im.save(img_name,"PNG") #final.paste(im, (int(x*largura), int(y*altura)))