def get_route_from_polyline(t):
    return pl.PolylineCodec().decode(t if isinstance(t, str) else t["polyline"])
Ejemplo n.º 2
0
from classes import LatLng
import polyline, util
from urllib import urlopen, quote
import xml.etree.ElementTree as ET
import time
import sys
import traceback
import json

Polyline = polyline.PolylineCodec()


class Geocoder(object):
    def __init__(self):
        self.next_query_time = time.time()
        self.max_failed_queries = 3

    def geocode(self, address, console, num, outof, attempt):
        '''Returns LatLng of Geocoding API'''
        if attempt == self.max_failed_queries:
            console.add('elevation', num, outof, False,
                        'Quitting this query. Data will be inaccurate')
            return None, False

        url = 'https://maps.googleapis.com/maps/api/geocode/json?address=' + address.replace(
            ' ', '+',
            len(address)) + '&key=AIzaSyCnHT7IpJu0O7n-apLNW8iKkW_rTIuANuE'

        current_time = time.time()
        if current_time < self.next_query_time:  #before earliest possible query time
            time.sleep(self.next_query_time -
def get_route_from_polyline(t):
    return pl.PolylineCodec().decode(t["polyline"])