# AUTOGENERATED! DO NOT EDIT! File to edit: nbs/distance.ipynb (unless otherwise specified).

__all__ = ['getDistanceOsrm']

# Cell
from beartype import beartype
from typing import List, Dict, Tuple
import yaml, requests

# Cell
@beartype
def getDistanceOsrm(lat1:float, lon1:float, lat2:float, lon2:float,
                    osrmEndpoint = 'http://router.project-osrm.org')->float:
  '''
    get driving distance between 2 points using osrm url
  '''
  url = f"{osrmEndpoint}/route/v1/bike/{lon1},{lat1};{lon2},{lat2}?overview=false"
  r = requests.get(url)
  try:
    distance = r.json()['routes'][0]['distance']
    return float(distance)
  except KeyError as e:
    raise KeyError(f"error getting distance got {r.json()} from urll \n{e}")
