def findBorderDistance( self ): # Used to find distance in degrees of latitude and longitude between edges of current tile centerPointObject = MercatorProjection.G_LatLng( self.coordinates[0], self.coordinates[1] ) # Gets MercatorProjection object for the centerpoint of this tile, used only on next line self.edges = MercatorProjection.getCorners( centerPointObject, self.zoom, self.pixelSize[0], self.pixelSize[1] ) # Uses MercatorProjection library to find edge coordinates of tile self.longitudinalLength = abs( self.edges['E'] - self.edges['W']) # Determine distance between edges of tile self.latitudinalLength = abs(self.edges['N'] - self.edges['S']) return (self.latitudinalLength, self.longitudinalLength)
def sms_reply(): # Start our response number = "" message_body = "" resp = MessagingResponse() #ewef w = 300 h = 500 if request: number = request.form['From'] message_body = request.form['Body'].split('|') unique_number = message_body[0] start = message_body[1] dest = message_body[2] getimage = message_body[3] if getimage == '1': [os.remove(os.path.join("./",f)) for f in os.listdir("./") if f.endswith(".png")] encoded = base64.b64encode(start + dest) encoded = str(encoded) + '.png' chrome_options = Options() chrome_options.add_argument("--headless") chrome_options.add_argument("--window-size=300,500") chrome_options.add_argument("--disable-gpu") chrome_options.add_argument("--disable-application-cache") chrome_options.add_argument("--incognito") driver = webdriver.Chrome(executable_path=os.path.abspath("chromedriver"), chrome_options=chrome_options) #driver.get("https://www.google.com/maps/dir/"+start+"/"+dest) #driver.get("https://timberwolf.herokuapp.com/map") driver.get("https://0f190fab.ngrok.io/map?start="+start+"&dest="+dest) driver.save_screenshot(encoded) driver.close() msg = resp.message("image") msg.media('https://4c3d3695.ngrok.io/uploads/{}'.format(encoded)) else: directions_result = gmaps.directions(start, dest, mode="driving", departure_time=datetime.now()) lats = list() lngs = list() lines = pline.decode(directions_result[0]['overview_polyline']['points']) for line in lines: lats.append(line[0]) lngs.append(line[1]) GLOBE_WIDTH = 256 #a constant in Google's map projection west = min(lngs) east = max(lngs) angle = east - west if angle < 0: angle += 360 north = max(lats) south = min(lats) anglens = abs(north) - abs(south) if anglens < 0: anglens += 360 zoomew = math.floor(math.log(w * 360 / angle / GLOBE_WIDTH) / 0.6931471805599453) zoomns = math.floor(math.log(h * 360 / anglens / GLOBE_WIDTH) / 0.6931471805599453) zoom = min(zoomew, zoomns) centerPoint = MercatorProjection.G_LatLng((min(lats)+max(lats))/2, (min(lngs)+max(lngs))/2) corners = MercatorProjection.getCorners(centerPoint, zoom, w, h) msg = resp.message(unique_number+"|" + str(corners['E']) + "|" + str(corners['N']) + "|" + str(corners['S']) + "|" + str(corners['W'])) return str(resp)