google.maps#

Description#

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

It requires you to create a Google application - you can create one at the developers console.

After that, you’ll need to create a new API key from the _Credentials_ tab.

This integration doesn’t require any additional scopes.

Configuration#

google.maps:
  # [Required]
  # Server-side API key to be used for the requests, get one at
  # https://console.developers.google.com
  api_key:   # type=str

  # [Optional]
  # List of scopes required by the API.
  # See https://developers.google.com/identity/protocols/oauth2/scopes
  # for a list of the available scopes. Override it in your configuration
  # only if you need specific scopes that aren't normally required by the
  # plugin.
  # scopes:   # type=Optional[Collection[str]]

  # [Optional]
  # Path to the client secrets file.
  # You can create your secrets.json from https://console.developers.google.com.
  # Default: ``<PLATYPUSH_WORKDIR>/credentials/google/client_secret.json``.
  # secrets_path:   # type=Optional[str]

Dependencies#

pip

pip install google-auth httplib2 oauth2client google-api-python-client

Alpine

apk add py3-google-auth py3-google-api-python-client py3-oauth2client py3-httplib2

Debian

apt install python3-google-auth python3-oauth2client python3-httplib2

Fedora

yum install python-google-api-client python-oauth2client python-httplib2 python-google-auth

Arch Linux

pacman -S python-google-api-python-client python-oauth2client python-httplib2 python-google-auth

Actions#

Module reference#

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

Bases: GooglePlugin

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

It requires you to create a Google application - you can create one at the developers console.

After that, you’ll need to create a new API key from the _Credentials_ tab.

This integration doesn’t require any additional scopes.

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

api_key – 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
  }
}