Last active
November 24, 2020 03:40
-
-
Save sergiolucero/bcb6c67d977942e7ab0cbe5846600990 to your computer and use it in GitHub Desktop.
here isolines
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from creds import ID,CODE # isolines: driving from my house | |
import folium | |
import requests | |
home =[-33.406654,-70.572701] # 085 LOS MILITARES / ALONSO DE CORDOVA | |
head = 'https://isoline.route.cit.api.here.com/routing/7.2/calculateisoline.json?' | |
URL_BASE = '{}app_id={}&app_code={}&mode=shortest;car;traffic:disabled&start=geo!{},{}&range={}&rangetype={}' | |
def isodata(home, range, type): | |
url = URL_BASE.format(head, ID, CODE, home[0],home[1], range, type) | |
js = requests.get(url).json()['response'] | |
center = js['center'] # {'latitude': -33.406654, 'longitude': -70.572701} | |
iso = js['isoline'] | |
comps = [(float(x.split(',')[0]),float(x.split(',')[1])) for x in iso[0]['component'][0]['shape']] | |
return comps | |
fm = folium.Map(location = home, zoom_start=13, tiles='CartoDBPositron') | |
for time, color in zip([60,300,600],['green','blue','red']): # 1,5,10 min | |
isoline = isodata(home, time, 'time') | |
folium.PolyLine(locations=isoline,color=color).add_to(fm) | |
fm.save('maida.html') |
Great example! Still works in 2018.
If you add the following code, it will even take into account the traffic situation in the rush hour time (in this example 2018-08-07T08:00:00 considered to be a time of high traffic - the start of working hours on a working day.)
&mode=fastest;car;traffic:enabled&departure=2018-08-07T08:00:00.
Works also with the free plan.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
All APIs listed here
Modes can be publicTransport, bicycle...