def gmap_image_large(fieldminlat,fieldmaxlat,fieldminlong,fieldmaxlong,tileminlat,tilemaxlat,tileminlong,tilemaxlong,fieldid,uid,fieldarea): import urllib.parse import urllib.request from io import StringIO from PIL import Image from math import log, exp, tan, atan, pi, ceil from latlontopixels import latlontopixels from pixelstolatlon import pixelstolatlon import io import math import os from getmapstaticcoords import getmapstaticcoords 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 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) pixelarea = abs(int(fieldarea)/100) print('pixel area') print(pixelarea) if pixelarea <300: zoom = 14 if pixelarea >300: zoom = 14 if pixelarea > 1200: zoom = 14 if pixelarea >5000: zoom = 13 if pixelarea > 40000: zoom = 12 latlen,longlen = getmapstaticcoords(centerlat,centerlong,zoom) PixelsPerLat = abs(10980/(tilemaxlat - tileminlat)) #PixelsPerLong = abs(10980/(tilemaxlong - tileminlong)) pixellatlen =round(latlen*PixelsPerLat) pixellonglen = pixellatlen if pixellatlen > pixellonglen: width = pixellatlen height = width else: width = pixellonglen height = width print('width'+str(width)+'height'+str(height)) if width > 1000: new_width = 1000 new_height = new_width*height/width width =round(new_width) height = round(new_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 = 'https://maps.googleapis.com/maps/api/staticmap?' + urlparams+'&key='+api_key print(url) f=urllib.request.urlopen(url) image_file = io.BytesIO(f.read()) im=Image.open(image_file) width1,height1 = im.size print(width) print(height) im = im.resize((width,height)) img_name = uid+"/"+str(fieldid)+'_static_map_large.png' im.save(img_name,"PNG") #final.paste(im, (int(x*largura), int(y*altura))) return latlen, longlen, centerlat, centerlong