Пример #1
0
def query_google(company_name, google_apikey, country_codes=None, additional_keywords=None):
    additional_keywords = ['plant'] if additional_keywords is None else additional_keywords
    google_maps = Client(key=google_apikey)

    if country_codes is None:
        raise Exception("""
        List of ISO 3166-1 alpha-2 country codes required, e.g. country_code_list=['DE']. 
        See https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 for codes.""")

    all_res = []

    for cc in country_codes:
        country_res = google_maps.places(' '.join([company_name] + additional_keywords), region=cc).get('results')
        if country_res:
            all_res += [r for r in country_res if
                        any(
                            [company_name.lower() in r.get(f, '').lower() for f in ['formatted_address', 'name']]) and
                        not any(
                            [term in r.get('formatted_address', '').lower() for term in
                                [f'near {company_name}', f'behind {company_name}']])]

    all_res = [r for r in all_res if not any([tag in r['types'] for tag in ['car_dealer', 'car_repair', 'store']])]

    addresses = pd.DataFrame([[d['name'],
                               d['formatted_address'],
                               d['geometry']['location']['lat'],
                               d['geometry']['location']['lng']]
                               for d in all_res], columns=['name', 'address', 'lat', 'lng'])

    addresses = addresses.assign(
        source='places_apis'
    )

    return addresses
Пример #2
0
now = datetime.now()
directions_result = gmaps.directions("Sydney Town Hall",
                                     "Parramatta, NSW",
                                     mode="transit",
                                     departure_time=now)

lat_long = (gmaps.geocode(
    '326 Perkins Library, Durham, NC 27708')[0]['geometry']['location']['lat'],
            gmaps.geocode('326 Perkins Library, Durham, NC 27708')[0]
            ['geometry']['location']['lng'])
print lat_long
duke = gmaps.reverse_geocode(lat_long)[0]['formatted_address']
print duke

local = gmaps.places('restaurant near ' + duke)
print local['results'][0]['formatted_address']
print local['results'][0]['name']

directions = gmaps.directions(duke, whitehouse)
print directions[0]['legs'][0]['distance']

for step in directions[0]['legs'][0]['steps']:
    print step['html_instructions']

embassies = [[38.917228, -77.0522365], [38.9076502, -77.0370427],
             [38.916944, -77.048739]]

# TODO: write code to answer the following questions:
# which embassy is closest to the White House in meters? how far?
destinations = []
def get_detail_from_address(address: str, client: googlemaps.Client):
    return client.places(address)
def get_postal_code_from_address(address: str, client: googlemaps.Client):
    return client.places(address)['results'][0]['formatted_address'][-6:]
Пример #5
0
query = st.text_input(label="What kind of place do you want to search for?")

radius = st.slider(label="Search Radius (m): ",
                   min_value=0,
                   max_value=25,
                   value=10)

op_time = st.radio("Place open now or later?: ", options=['Now', 'Later'])

if (address != '') and (query != ''):
    geocode_result = gmaps.geocode(address)
    latitude = geocode_result[0]['geometry']['location']['lat']
    longitude = geocode_result[0]['geometry']['location']['lng']
    lat_long = (latitude, longitude)
    results = gmaps.places(query=query,
                           radius=radius,
                           location=lat_long,
                           open_now=True)
    headers = results['results'][0].keys()
    data_path = str(query) + str(now)
    data_path = f'{data_path}' + '.csv'

    with open(data_path, 'w') as f:
        dict_writer = csv.DictWriter(f, headers)
        dict_writer.writeheader()
        dict_writer.writerows(results['results'])
    nr = nearest_restaurants(f"{data_path}")
    st.write("## Objectives: ")

    st.write("- Transforming Coordinates Into Data via Google Maps API")
    st.write("- Visualizing Data on a Map")
Пример #6
0
now = datetime.now()
directions_result = gmaps.directions("Sydney Town Hall",
                                     "Parramatta, NSW",
                                     mode="transit",
                                     departure_time=now)

lat_long = (gmaps.geocode(
    '326 Perkins Library, Durham, NC 27708')[0]['geometry']['location']['lat'],
            gmaps.geocode('326 Perkins Library, Durham, NC 27708')[0]
            ['geometry']['location']['lng'])
print lat_long
duke = gmaps.reverse_geocode(lat_long)[0]['formatted_address']
print duke

local = gmaps.places('restaurant near ' + duke)
print local['results'][0]['formatted_address']
print local['results'][0]['name']

directions = gmaps.directions(duke, whitehouse)
print directions[0]['legs'][0]['distance']

for step in directions[0]['legs'][0]['steps']:
    print step['html_instructions']
embassies = [[38.917228, -77.0522365], [38.9076502, -77.0370427],
             [38.916944, -77.048739]]


def nearest_embassy(wh, embassy_list):
    e_dist = distances(wh, embassy_list)
    shortest = min(e_dist)