Esempio n. 1
0
def geocode_google_place(address):
    google_url = 'https://maps.googleapis.com/maps/api/geocode/json?address={}&sensor=false&key={}'.format(
        address,
        Config.get_env_var('GOOGLE_API_KEY'),
    )
    r = requests.get(url=google_url)
    if r.status_code != 200:
        raise ValueError('Unknown/Not Finished Error Occured: {}'.format(
            r.text))
    return r.json()
Esempio n. 2
0
def search_google_places(type, text):
    google_url = 'https://maps.googleapis.com/maps/api/place/autocomplete/json?&input={}&key={}'.format(
        text,
        Config.get_env_var('GOOGLE_API_KEY'),
    )
    # google_url = 'https://maps.googleapis.com/maps/api/place/autoComplete/json?types=establishment&input={}&key={}'.format(
    #     text,
    #     Config.get_env_var('GOOGLE_API_KEY'),
    # )
    r = requests.get(url=google_url)
    if r.status_code != 200:
        raise ValueError('Unknown/Not Finished Error Occured: {}'.format(
            r.text))
    return r.json()
Esempio n. 3
0
def get_google_directions(origin, destination, waypoints):
    new_waypoints = ''
    for waypoint in waypoints:
        new_waypoints += '{}'.format(waypoint) + '|'
    print(new_waypoints)
    google_url = 'https://maps.googleapis.com/maps/api/directions/json?origin={}&destination={}&key={}'.format(
        # google_url = 'https://maps.googleapis.com/maps/api/directions/json?origin={}&destination={}&waypoints=optimize:true|{}&key={}'.format(
        origin,
        destination,
        # new_waypoints,
        Config.get_env_var('GOOGLE_API_KEY'),
    )
    r = requests.get(url=google_url)
    if r.status_code == 200:
        print(r.json())
        return r.json()
    raise ValueError('Unknown Google Directions Error Occured: {}'.format(
        r.text))