Ejemplo n.º 1
0
    def add_direction(self, fig, origin, destination, mode='DRIVING'):
        '''
        Add direction to the map 

        arguments:
        ----------
        fig         - figure object
        origin      - starting point
        destination - end point

        return:
        -------
        fig         - enriched figure object 
        '''
        stroke_color = 'red',
        stroke_opacity = 1.0
        stroke_weight = 2.0

        color_palette = [
            '#eb4034', '#4a9932', '#3b8796', '#4e64cf', '#a14bcc', '#ab203c'
        ]
        color = random.choice(color_palette)

        direction = gmaps.directions_layer(origin,
                                           destination,
                                           stroke_color=color,
                                           stroke_opacity=stroke_opacity,
                                           stroke_weight=stroke_weight,
                                           travel_mode='DRIVING')
        fig.add_layer(direction)
        return fig
Ejemplo n.º 2
0
def geneva2zurich():

    geneva = (46.2, 6.1)
    montreux = (46.4, 6.9)
    zurich = (47.4, 8.5)
    fig = gmaps.figure()
    geneva2zurich = gmaps.directions_layer(geneva, zurich)

    return geneva, zurich, geneva2zurich
Ejemplo n.º 3
0
def render_closures(data):
    # import modules for the python script:
    import pandas as pd
    import gmaps
    import time

    # layout options: draw a comfortable-sized map
    figure_layout = {
        'width': '700px',
        'height': '400px',
        'padding': '1px',
        'margin': '0 auto 0 auto'
    }
    # initialize map
    fig = gmaps.figure(layout=figure_layout)

    # establish list for map markers
    marker_coords = []
    marker_labels = []

    # draw road closures
    for index, _ in data.iterrows():
        # The parameters are mostly self-explanatory, but I will note that this uses
        # walking directions in case start and end points are contrary to one-way streets
        close = gmaps.directions_layer(start=data.iloc[index][0],
                                       end=data.iloc[index][1],
                                       travel_mode='DRIVING',
                                       show_markers=False,
                                       stroke_color='Red',
                                       stroke_opacity=0.8)
        # add this closure's layer
        fig.add_layer(close)
        # check for label text:
        if data.iloc[index][2] is not None:
            # append label info (I'm not really happy with how these end up looking, but
            # we're on a time crunch. Function over form, I say!)
            marker_coords.append(data.iloc[index][0])
            marker_labels.append(data.iloc[index][2])

        # Google Maps API limits to 50 requests per second
        time.sleep(0.3)

    # if marker_labels isn't empty
    if marker_labels != []:
        # establish labeled markers
        marker_layer = gmaps.marker_layer(locations=marker_coords,
                                          label=marker_labels)
        # and add them to the map
        fig.add_layer(marker_layer)
    return fig
Ejemplo n.º 4
0
def find_path(start, end, method = 'BICYCLING'):
    "Method could be 'DRIVING','WALKING','BICYCLING','TRANSIT'"
    my_key = api_key
    gmaps.configure(api_key=my_key)
    
    start = str(start)
    end = str(end)
    start_location = get_location(start)
    end_location = get_location(end)
    
    fig = gmaps.figure()
    path = gmaps.directions_layer(start_location, end_location, travel_mode= method)#we can add waypoints and travel_mode
    fig.add_layer(path)

    return fig
Ejemplo n.º 5
0

class Empty:
    pass


#
cidade = Empty()
cidade.data = geolocator.geocode("campina grande, Paraiba")
cidade.coordinates = (cidade.data.latitude, cidade.data.longitude)
#
bombeiros1 = Empty()
bombeiros1.data = geolocator.geocode(
    "2º Batalhão de Bombeiro Militar, Av. Prof. Almeida Barreto,<campina grande>"
)
bombeiros1.coordinates = (bombeiros1.data.latitude, bombeiros1.data.longitude)
#
bombeiros2 = Empty()
bombeiros2.data = geolocator.geocode("Aeroporto, Campina Grande")
bombeiros2.coordinates = (bombeiros2.data.latitude, bombeiros2.data.longitude)
#
print(bombeiros1.coordinates, bombeiros2.coordinates, cidade.coordinates)
#
gmaps.configure(api_key="AIzaSyB1MhfDz7x85UyTWQEqtAnKy_4aUwt2HDI")
fig = gmaps.figure(cidade.coordinates, map_type='ROADMAP')
rota1 = gmaps.directions_layer(bombeiros2.coordinates,
                               bombeiros1.coordinates,
                               waypoints=[cidade.coordinates])
fig.add_layer(rota1)
fig.add_layer(gmaps.transit_layer())
fig
Ejemplo n.º 6
0
addr_to = '710 Front St, Santa Cruz, CA 95060'
addr_f = addr_from.replace(' ', '+')
addr_t = addr_to.replace(' ', '+')

addr_f = addr_from.replace(' ', '%20')

url_f = f'https://maps.googleapis.com/maps/api/place/findplacefromtext/json?input={addr_f}&inputtype=textquery&fields=geometry&key=' + api_key
res_f = requests.get(url_f)
result_f = res_f.json()
loc_from = result_f['candidates'][0]['geometry']['location']['lat'], result_f[
    'candidates'][0]['geometry']['location']['lng']

url_f = f'https://maps.googleapis.com/maps/api/geocode/json?address={addr_f}&key={api_key}'
url_t = f'https://maps.googleapis.com/maps/api/geocode/json?address={addr_t}&key={api_key}'

res_f = requests.get(url_f)
result_f = res_f.json()
res_t = requests.get(url_t)
result_t = res_t.json()

loc_from = (result_f['results'][0]['geometry']['location']['lat'],
            result_f['results'][0]['geometry']['location']['lng'])
loc_to = (result_t['results'][0]['geometry']['location']['lat'],
          result_t['results'][0]['geometry']['location']['lng'])

gmaps.configure(api_key)
fig = gmaps.figure()
loc_from2loc_to = gmaps.directions_layer(loc_from, loc_to)
fig.add_layer(loc_from2loc_to)
fig
Ejemplo n.º 7
0
disp_lat = test['dispatch_location_lat'].tolist()
disp_long = test['dispatch_location_long'].tolist()
start_lat = test['start_location_lat'].tolist()
start_long = test['start_location_long'].tolist()
end_lat = test['end_location_lat'].tolist()
end_long = test['end_location_long'].tolist()
end_lat_prev = test['end_lat_prev'].tolist()
end_long_prev = test['end_long_prev'].tolist()

fig = gmaps.figure()
for i in range(5):
    prev_end = (end_lat_prev[i],end_long_prev[i])
    dispatch = (disp_lat[i], disp_long[i])
    start = (start_lat[i], start_long[i])
    end = (end_lat[i], end_long[i])
    route = gmaps.directions_layer(prev_end,end,waypoints = [dispatch,start])
    fig.add_layer(route)
    
fig.add_layer(prev_end_layer)
fig.add_layer(dispatch_layer)
fig.add_layer(start_layer)
fig.add_layer(end_layer)
fig.add_layer(interest_layer)

fig._map.layout.width = '1000px'
fig._map.layout.height = '1000px' 

fig
#red - dispatch
#green - start
#blue - end
Ejemplo n.º 8
0
# %%
#  Lat and longitude of Camopi city
camarillo_latlng = tuple(zip(camarillo_df['Lat'], camarillo_df['Lng']))[0]
camarillo_latlng

# %%
#  Lat and longitude of Camopi city
pahrump_latlng = tuple(zip(pahrump_df['Lat'], pahrump_df['Lng']))[0]
pahrump_latlng

# %%
fig = gmaps.figure()
pacgrove2pahrump_via_lompoc_camarillo = gmaps.directions_layer(
    pacgrove_latlng,
    pahrump_latlng,
    waypoints=[lompoc_latlng, camarillo_latlng],
    travel_mode='DRIVING')
#geneva2zurich_via_montreux = gmaps.directions_layer(
#geneva, zurich, waypoints=[montreux],
#travel_mode='Driving')
fig.add_layer(pacgrove2pahrump_via_lompoc_camarillo)
fig
# %%
# Create one dataframe for the four cities
cities_conc = [pacgrove_df, lompoc_df, camarillo_df, pahrump_df]
cities_conc_df = pd.concat(cities_conc)
cities_conc_df
#result = pd.concat(frames)
# %%
info_box_template = """
Ejemplo n.º 9
0
import gmaps
import gmaps.datasets
gmaps.configure(api_key='AIzaSyAvTQCGl03_PMRmJM6lFVWK7OI_GrdoYn8')

# Latitude-longitude pairs
origin = (12.861806, 77.664670)
destination = (12.870464, 77.659501)

trashcans = [(12.863914, 77.656840)]

fig = gmaps.figure()
route = gmaps.directions_layer(origin, destination, waypoints=trashcans)
fig.add_layer(route)
fig