Skip to content

Commit 5a94246

Browse files
Merge pull request #353 from phenobarbital/dev
fix on waypoint route
2 parents 1222fe9 + fc1525f commit 5a94246

3 files changed

Lines changed: 10 additions & 4 deletions

File tree

navigator/actions/google/maps.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,7 @@ async def waypoint_route(
388388
"travelMode": payload.travel_mode,
389389
"routingPreference": payload.routing_preference or "TRAFFIC_AWARE",
390390
"computeAlternativeRoutes": False,
391+
"optimizeWaypointOrder": False,
391392
"routeModifiers": {
392393
"avoidTolls": False,
393394
"avoidHighways": False,
@@ -475,6 +476,7 @@ async def waypoint_route(
475476
static_duration += int(static_duration_str.rstrip('s'))
476477
# Distance:
477478
distance_meters = leg.get('distanceMeters', 0)
479+
distance_miles = distance_meters / 1609.34 if distance_meters else 0
478480
total_distance += distance_meters
479481
if leg.get('steps') and len(leg['steps']) > 0:
480482
# Get the first step's navigation instruction
@@ -484,13 +486,13 @@ async def waypoint_route(
484486
# Get localized distance for this leg
485487
leg_distance = leg.get(
486488
'localizedValues', {}
487-
).get('distance', {}).get('text', f"{leg['distanceMeters']/1609.34:.1f} mi") or f"{distance_meters/1609.34:.1f} mi" # noqa: E501
489+
).get('distance', {}).get('text', f"{distance_miles:.1f} mi") # noqa: E501
488490
bestroute.append(f"Leg {i+1}: {instruction} for {leg_distance}")
489491
else:
490492
# Fallback if no navigation instruction
491493
leg_distance = leg.get(
492494
'localizedValues', {}
493-
).get('distance', {}).get('text', f"{leg['distanceMeters']/1609.34:.1f} mi") or f"{distance_meters/1609.34:.1f} mi" # noqa: E501
495+
).get('distance', {}).get('text', f"{distance_miles:.1f} mi") # noqa: E501
494496
bestroute.append(f"Leg {i+1}: Continue for {leg_distance}")
495497
# Convert duration to minutes
496498
total_duration_min = total_duration / 60 if total_duration > 0 else 0

navigator/actions/google/models.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Union
1+
from typing import Union, Optional
22
from datetime import datetime
33
from datamodel import BaseModel, Field
44

@@ -10,6 +10,10 @@ class Location(BaseModel):
1010
address: str = Field(required=False, label="Address")
1111
place_id: str = Field(required=False)
1212
formatted_address: str = Field(required=False)
13+
timestamp: Optional[datetime] = Field(
14+
required=False,
15+
description="Timestamp of the location data"
16+
)
1317

1418
class Meta:
1519
strict: bool = True

navigator/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
__description__ = (
55
"Navigator Web Framework based on aiohttp, " "with batteries included."
66
)
7-
__version__ = "2.12.26"
7+
__version__ = "2.12.27"
88
__copyright__ = "Copyright (c) 2020-2024 Jesus Lara"
99
__author__ = "Jesus Lara"
1010
__author_email__ = "jesuslarag@gmail.com"

0 commit comments

Comments
 (0)