google.maps#

class platypush.plugins.google.maps.GoogleMapsPlugin(api_key, *args, **kwargs)[source]#

Bases: GooglePlugin

Plugins that provides utilities to interact with Google Maps API services.

Requires:

  • google-api-python-client (pip install google-api-python-client)

  • oauth2client (pip install oauth2client)

__init__(api_key, *args, **kwargs)[source]#
Parameters:

api_key (str) – Server-side API key to be used for the requests, get one at https://console.developers.google.com

get_address_from_latlng(latitude, longitude)[source]#

Get an address information given lat/long

Parameters:
  • latitude (float) – Latitude

  • longitude (float) – Longitude

get_elevation_from_latlng(latitude, longitude)[source]#

Get the elevation in meters of a geo point given lat/long

Parameters:
  • latitude (float) – Latitude

  • longitude (float) – Longitude

get_travel_time(origins: List[str], destinations: List[str], departure_time: str | int | float | datetime | None = None, arrival_time: str | int | float | datetime | None = None, units: str = 'metric', avoid: List[str] | None = None, language: str | None = None, mode: str | None = None, traffic_model: str | None = None, transit_mode: List[str] | None = None, transit_route_preference: str | None = None)[source]#

Get the estimated travel time between a set of departure points and a set of destinations.

Parameters:
  • origins

    The starting point(s) for calculating travel distance and time. Locations are supplied in the form of a place ID, an address, or latitude/longitude coordinates:

    • Place ID: If you supply a place ID, you must prefix it with place_id:.

    • Address: If you pass an address, the service geocodes the string and converts it to a latitude/longitude coordinate to calculate distance.

    • Coordinates: If you pass latitude/longitude coordinates, they they will snap to the nearest road.

  • destinations

    The arrival point(s) for calculating travel distance and time. Locations are supplied in the form of a place ID, an address, or latitude/longitude coordinates:

    • Place ID: If you supply a place ID, you must prefix it with place_id:.

    • Address: If you pass an address, the service geocodes the string and converts it to a latitude/longitude coordinate to calculate distance.

    • Coordinates: If you pass latitude/longitude coordinates, they they will snap to the nearest road.

  • departure_time – Preferred departure time, as a UNIX timestamp, an ISO8601 string or a datetime object.

  • arrival_time – Preferred arrival time, as a UNIX timestamp, an ISO8601 string or a datetime object.

  • unitsmetric (default) or imperial.

  • avoid

    Any of the following values:

    • tolls: indicates that the calculated route should avoid toll roads/bridges.

    • highways: indicates that the calculated route should avoid highways.

    • ferries: indicates that the calculated route should avoid ferries.

    • indoor indicates that the calculated route should avoid indoor steps for walking and transit directions.

  • language – Target language for the results (ISO string). If none is specified then the target language is inferred from the Accept-Language header or the preferred language associated to the account.

  • mode

    Any of the following:

    • DRIVING (default)

    • WALKING

    • BICYCLING

    • TRANSIT

  • traffic_model

    Specifies the assumptions to use when calculating time in traffic. This setting affects the value returned in the duration_in_traffic field in the response, which contains the predicted time in traffic based on historical averages. Available values:

    • best_guess (default) indicates that the returned duration_in_traffic should be the best

      estimate of travel time given what is known about both historical traffic conditions and live traffic. Live traffic becomes more important the closer the departure_time is to now.

    • pessimistic indicates that the returned duration_in_traffic should be longer than the actual travel time on most days, though occasional days with particularly bad traffic conditions may exceed this value.

    • optimistic indicates that the returned duration_in_traffic should be shorter than the actual travel time on most days, though occasional days with particularly good traffic conditions may be faster than this value.

  • transit_mode

    Specifies one or more preferred modes of transit. This parameter may only be specified for transit directions. Available values:

    • bus indicates that the calculated route should prefer travel by bus.

    • subway indicates that the calculated route should prefer travel by subway.

    • train indicates that the calculated route should prefer travel by train.

    • tram indicates that the calculated route should prefer travel by tram and light rail.

    • rail indicates that the calculated route should prefer travel by train, tram, light rail, and

      subway. This is equivalent to transit_mode=["train", "tram", "subway"].

  • transit_route_preference

    Specifies preferences for transit routes. Using this parameter, you can bias the options returned, rather than accepting the default best route chosen by the API. This parameter may only be specified for transit directions. Available values:

    • less_walking indicates that the calculated route should prefer limited amounts of walking.

    • fewer_transfers indicates that the calculated route should prefer a limited number of transfers.

Returns:

{
  "distance": {
    "text": "6.5 km",
    "value": 6542
  },
  "duration": {
    "text": "13 mins",
    "value": 777
  }
}