Exemple #1
0
 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)
Exemple #2
0
# create url 
# can change variables to center on certain locations
# size maxes out at 640x640 for free version
# -90 < latitude < 90       -180 < longitude < 180
def getUrl(latitude, longitude, zoom, horizontal, vertical):
    apikey = "AIzaSyA4it7lRdo5H0mhPlRMM4n2CltZpFnnF4s";
    query = "https://maps.googleapis.com/maps/api/staticmap?"
    query += "center=%s,%s&" % (latitude,longitude)
    query += "zoom=%s&" % zoom
    query += "size=%sx%s&" % (horizontal,vertical)
    query += apikey
    return query


centerPoint = MercatorProjection.G_LatLng(0, 0)
corners = MercatorProjection.getCorners(centerPoint, 10, 640, 640)

# on a webpage right click on the image you want and use Copy image URL
image_url = getUrl(0, 0, 10, 640, 640)

# caches the image in same directory
urllib.urlretrieve(image_url, "00000002.jpg")

# opens image
image_str = urlopen(image_url).read()

# create a file object (stream)
image_file = io.BytesIO(image_str)

# create an x by y white screen and put the image on that screen
def display(x,y):
import location_history_json_converter
import MercatorProjection
import LatitudePlot
import StringIO

path = '/home/TheR3ason/map-your-location-history/'

c = location_history_json_converter.convert()
json = open(path+'LocationHistory.json')
converted = c.main(json)
print 'converted that shit'
center = converted[1]
kml = converted[0].getvalue()
print kml

centerLat = center['latitude']
centerLon = center['longitude']
zoom = 6
mapWidth = 640
mapHeight = 640
centerPoint = MercatorProjection.G_LatLng(centerLat, centerLon)
corners = MercatorProjection.getCorners(centerPoint, zoom, mapWidth, mapHeight)
mapURL = "http://maps.googleapis.com/maps/api/staticmap?center=%f,%f&zoom=%d&size=%dx%d&scale=2&maptype=roadmap&sensor=false"%(centerLat,centerLon,zoom,mapWidth,mapHeight)


import urllib
f = open(path+'staticimage.png','wb')
f.write(urllib.urlopen(mapURL).read())
f.close()

LatitudePlot.DrawMapData(kml ,path+'staticimage.png', path+"LatitudeData.png", corners['N'], corners['S'], corners['W'], corners['E'],0,0)
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)
Exemple #5
0
 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)
Exemple #6
0
def findCorners(latitude, longitude, zoom, horizontal, vertical):
    centerPoint = MercatorProjection.G_LatLng(latitude, longitude)
    corners = MercatorProjection.getCorners(centerPoint, zoom, horizontal, vertical)
    return corners