find driving distance using bing and osrm api

osrm

getDistanceOsrm[source]

getDistanceOsrm(lat1:float, lon1:float, lat2:float, lon2:float, osrmEndpoint='http://router.project-osrm.org')

get driving distance between 2 points using osrm url

%%time
#example
testData = '''
lat1 : 13.732048
lon1 : 100.567623
lat2 : 13.856271
lon2 : 100.546467
'''
i = yaml.load(testData, Loader=yaml.FullLoader)
f'the distance is {getDistanceOsrm(**i)} m'
CPU times: user 5.53 ms, sys: 221 µs, total: 5.75 ms
Wall time: 770 ms
'the distance is 17608.5 m'

get distance bing

getDistBing[source]

getDistBing(origin:Tuple[float, float], destinations:List[Tuple[float, float]], bingApiKey:str='')

accept a list of tuple origins and destinations, return a dataframe input: origin :: Tuple[float,float] : (lat,long) of the origin destinations:: List[Tuple[float,float]]: [(lat,long),(lat,long)] of the destinations bingApiKey:str:: apikey from bing map response: pd.DataFrame with [dist, dur, lat, long] as indexes, all in float, all distances in m and time in s

from nicHelper.secrets import getSecret
testData = '''
origin:
  !!python/tuple
  - 13.732048
  - 100.567623
destinations:
  -  !!python/tuple
    - 13.856271
    - 100.546467
  -  !!python/tuple
    - 13.856444
    - 100.549487
  - !!python/tuple
    - 13.857444
    - 100.549487
'''
i = yaml.load(testData, Loader = yaml.FullLoader)

apikey = getSecret( name = 'webApiKeys')['bing']
results = getDistBing( **i, bingApiKey = apikey )
results
# print(f'distances are {dist}, time taken are {timetaken}')
dist dur lat long
0 18.208 25.7167 13.856271 100.546467
1 18.812 27.2167 13.856444 100.549487
2 19.490 29.3833 13.857444 100.549487