Skip to content
This repository has been archived by the owner on Nov 28, 2024. It is now read-only.

Implementation for the google maps #31

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion backend/app/tool/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from .searchOnlineTool import fetch_web_page, search_duckduckgo
from .getStopsTool import get_all_stop_times
from .googleMapsTool import google_maps_navigation

FUNCTION_MAPPING = {
"fetch_web_page": fetch_web_page,
"search_duckduckgo": search_duckduckgo,
"get_all_stop_times": get_all_stop_times
"get_all_stop_times": get_all_stop_times,
"google_maps_navigation": google_maps_navigation
}

63 changes: 63 additions & 0 deletions backend/app/tool/googleMapsTool.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
from app.tool.gtfs.data_loader import GTFS_data
import googlemaps
import json

api_key = "YOUR_GOOGLE_MAPS_API_KEY"

def google_maps_navigation(start_longitude, start_latitude, destination_longitude, destination_latitude, api_key=api_key):
"""
Utilizes the Google Maps API to return the full navigation path given the longitude and latitude of the start and destination points.

Parameters:
- start_longitude (float): The longitude of the starting point.
- start_latitude (float): The latitude of the starting point.
- end_longitude (float): The longitude of the destination point.
- end_latitude (float): The latitude of the destination point.
- api_key (str): The API key for accessing Google Maps services.

Returns:
- dict: The navigation path details.
"""
gmaps = googlemaps.Client(key=api_key)

# Request directions via driving mode
directions_result = gmaps.directions(
(start_latitude, start_longitude),
(destination_latitude, destination_longitude),
mode="driving"
)

if not directions_result:
return {"error": "No route found"}

# Extract the relevant information from the directions result
route = directions_result[0]
legs = route.get("legs", [])
steps = []

for leg in legs:
for step in leg.get("steps", []):
steps.append({
"start_location": step["start_location"],
"end_location": step["end_location"],
"instructions": step["html_instructions"],
"distance": step["distance"]["text"],
"duration": step["duration"]["text"]
})

return {
"start_location": {"lat": start_latitude, "lng": start_longitude},
"end_location": {"lat": destination_latitude, "lng": destination_longitude},
"steps": steps
}

# Example usage
""" if __name__ == "__main__":
api_key = "YOUR_GOOGLE_MAPS_API_KEY"
start_longitude = -122.084
start_latitude = 37.422
end_longitude = -122.084
end_latitude = 37.422
navigation_path = google_maps_navigation(start_longitude, start_latitude, end_longitude, end_latitude, api_key)
print(json.dumps(navigation_path, indent=2)) """

34 changes: 34 additions & 0 deletions backend/storage/tool/tool_register.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,39 @@
]
}
}
},
{
"type": "function",
"function": {
"name": "google_maps_navigation",
"description": "Utilizes the Google Maps API to return the full navigation path given the longitude and latitude of the start and destination points.",
"parameters": {
"type": "object",
"properties": {
"start_longitude": {
"type": "number",
"description": "The longitude of the starting point."
},
"start_latitude": {
"type": "number",
"description": "The latitude of the starting point."
},
"destination_longitude": {
"type": "number",
"description": "The longitude of the destination point."
},
"destination_latitude": {
"type": "number",
"description": "The latitude of the destination point."
}
},
"required": [
"start_longitude",
"start_latitude",
"destination_longitude",
"destination_latitude"
]
}
}
}
]
29 changes: 29 additions & 0 deletions backend/storage/tool/tool_register_TODO.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,34 @@
]
}
}
},
{
"type": "function",
"function": {
"name": "local_traffic_prediction",
"description": "Predicts traffic patterns and potential congestion using locally stored historical and real-time traffic data.",
"parameters": {
"type": "object",
"properties": {
"prediction_window": {
"type": "integer",
"description": "The time window (in minutes or hours) for which the model should predict future traffic conditions."
},
"update_interval": {
"type": "integer",
"description": "The interval at which real-time data should update predictions."
},
"region": {
"type": "string",
"description": "The region or area within the city for which traffic predictions should be made."
}
},
"required": [
"prediction_window",
"update_interval",
"region"
]
}
}
}
]