Spaces:
Sleeping
Sleeping
Download app/services/maps.py from Sherry245/rideshare-api: direct link, hf CLI and curl.
- Browser
- Download file 770 Bytes
-
https://huggingface.co/spaces/Sherry245/rideshare-api/resolve/main/app/services/maps.py
- Command line
-
hf download hf://spaces/Sherry245/rideshare-api/app/services/maps.py
-
curl -L -o maps.py https://huggingface.co/spaces/Sherry245/rideshare-api/resolve/main/app/services/maps.py
770 Bytes
| import math | |
| from app.schemas.rides import Coordinate | |
| async def google_directions(pickup: Coordinate, dropoff: Coordinate) -> tuple[float, float]: | |
| # TODO: replace with real Google Directions API call (needs httpx + GOOGLE_MAPS_KEY). | |
| distance_km = _haversine_km(pickup.lat, pickup.lng, dropoff.lat, dropoff.lng) | |
| duration_min = (distance_km / 30.0) * 60.0 | |
| return round(distance_km, 2), round(duration_min, 1) | |
| def _haversine_km(lat1: float, lng1: float, lat2: float, lng2: float) -> float: | |
| R = 6371.0 | |
| p1, p2 = math.radians(lat1), math.radians(lat2) | |
| dp = math.radians(lat2 - lat1) | |
| dl = math.radians(lng2 - lng1) | |
| a = math.sin(dp / 2) ** 2 + math.cos(p1) * math.cos(p2) * math.sin(dl / 2) ** 2 | |
| return 2 * R * math.asin(math.sqrt(a)) | |