Camel.toolkits.google maps toolkit
handle_googlemaps_exceptions
Decorator to catch and handle exceptions raised by Google Maps API calls.
Parameters:
- func (Callable): The function to be wrapped by the decorator.
Returns:
Callable: A wrapper function that calls the wrapped function and handles exceptions.
_format_offset_to_natural_language
Converts a time offset in seconds to a more natural language description using hours as the unit, with decimal places to represent minutes and seconds.
Parameters:
- offset (int): The time offset in seconds. Can be positive, negative, or zero.
Returns:
str: A string representing the offset in hours, such as “+2.50 hours” or “-3.75 hours”.
GoogleMapsToolkit
A class representing a toolkit for interacting with GoogleMaps API. This class provides methods for validating addresses, retrieving elevation, and fetching timezone information using the Google Maps API.
init
get_address_description
Validates an address via Google Maps API, returns a descriptive summary. Validates an address using Google Maps API, returning a summary that includes information on address completion, formatted address, location coordinates, and metadata types that are true for the given address.
Parameters:
- address (Union[str, List[str]]): The address or components to validate. Can be a single string or a list representing different parts.
- region_code (str, optional): Country code for regional restriction, helps narrow down results. (default: :obj:
None
) - locality (str, optional): Restricts validation to a specific locality, e.g., “Mountain View”. (default: :obj:
None
)
Returns:
str: Summary of the address validation results, including information on address completion, formatted address, geographical coordinates (latitude and longitude), and metadata types true for the address.
get_elevation
Retrieves elevation data for a given latitude and longitude. Uses the Google Maps API to fetch elevation data for the specified latitude and longitude. It handles exceptions gracefully and returns a description of the elevation, including its value in meters and the data resolution.
Parameters:
- lat (float): The latitude of the location to query.
- lng (float): The longitude of the location to query.
Returns:
str: A description of the elevation at the specified location(s), including the elevation in meters and the data resolution. If elevation data is not available, a message indicating this is returned.
get_timezone
Retrieves timezone information for a given latitude and longitude. This function uses the Google Maps Timezone API to fetch timezone data for the specified latitude and longitude. It returns a natural language description of the timezone, including the timezone ID, name, standard time offset, daylight saving time offset, and the total offset from Coordinated Universal Time (UTC).
Parameters:
- lat (float): The latitude of the location to query.
- lng (float): The longitude of the location to query.
Returns:
str: A descriptive string of the timezone information, including the timezone ID and name, standard time offset, daylight saving time offset, and total offset from UTC.
get_tools
Returns:
List[FunctionTool]: A list of FunctionTool objects representing the functions in the toolkit.