View Source ExMaps (ExMaps v1.1.3)

Public ExMaps application interface.

This module provides functions to interact with the Google Maps API, offering directions and distance matrix calculations.

Summary

Types

Required parameters for directions API request.

Represents destinations for a distance matrix request.

Required parameters for distance matrix API request.

Optional parameters shared across API requests.

Represents origins for a distance matrix request.

Format of the output of Google Maps API call. Please note that JSON is recommended by Google docs.

Protocol type used for the request, defaults to HTTPS.

Time-to-live for cached results.

Represents a waypoint, which can be a string, a tuple of latitude/longitude, or a map with a place ID.

Functions

Returns calculated directions between provided locations.

Returns travel distance and time for a matrix of origins and destinations.

Types

@type alternatives() :: boolean()
@type arrival_time() :: integer()
@type avoid() :: [avoid_value()]
@type avoid_value() :: :tolls | :highways | :ferries | :indoor
@type coordinates() :: [%{origin: waypoint(), destination: waypoint()}]

Required parameters for directions API request.

@type departure_time() :: integer()
@type destinations() :: String.t() | {float(), float()} | %{place_id: String.t()}

Represents destinations for a distance matrix request.

@type language() :: String.t()
@type matrix_coordinates() :: [%{origins: [waypoint()], destinations: [waypoint()]}]

Required parameters for distance matrix API request.

@type mode() :: :driving | :walking | :bicycling | :transit

Optional parameters shared across API requests.

  • mode - Specifies the mode of transport to use when calculating directions. Defaults to driving.
  • waypoints - A list of waypoints.
  • alternatives - If set to true, API may provide more than one route alternative.
  • avoid - List of specific routes to avoid.
  • language - Directions may be provided in specified language (not all JSON/XML answer fields).
  • units - If not present, unit system of the origin's country or region will be returned.
  • region - Biasing on a specific region.
  • arrival_time - Desired arrival time in seconds since midnight, January 1, 1970 UTC.
  • departure_time - Desired departure time in seconds since midnight, January 1, 1970 UTC.
  • traffic_model - May only be specified for driving directions where the request includes a departure_time.
  • transit_mode - May only be specified for transit directions.
  • transit_routing_preference - May bias the options returned.
@type options() :: [{option(), term()}]
@type origins() :: String.t() | {float(), float()} | %{place_id: String.t()}

Represents origins for a distance matrix request.

@type output_format() :: :json | :xml

Format of the output of Google Maps API call. Please note that JSON is recommended by Google docs.

@type protocol() :: :https | :http

Protocol type used for the request, defaults to HTTPS.

@type region() :: String.t()
@type traffic_model() :: :best_guess | :pessimistic | :optimistic
@type transit_mode() :: :bus | :subway | :train | :tram | :rail
Link to this type

transit_routing_preference()

View Source
@type transit_routing_preference() :: :less_walking | :fewer_transfers
@type ttl() :: integer()

Time-to-live for cached results.

@type units() :: :metric | :imperial
@type waypoint() :: String.t() | {float(), float()} | %{place_id: String.t()}

Represents a waypoint, which can be a string, a tuple of latitude/longitude, or a map with a place ID.

@type waypoints() :: :waypoints

Functions

Link to this function

get_directions(coordinates, options \\ [])

View Source
@spec get_directions(coordinates(), options()) :: [map()]

Returns calculated directions between provided locations.

Checks whether the directions with the same set of options have already been calculated and cached. If not, it calls the Google API, fetches the result, saves it in cache, and returns it.

Examples

iex> ExMaps.get_directions([%{origin: "Warsaw", destination: "Amsterdam"}], units: :metric)
[%{"geocoded_waypoints" => ... }]
Link to this function

get_distance_matrix(matrix_coordinates, options \\ [])

View Source
@spec get_distance_matrix(matrix_coordinates(), options()) :: [map()]

Returns travel distance and time for a matrix of origins and destinations.

Checks whether the matrix with the same set of options has already been requested and cached. If not, it calls the Google API, fetches the result, saves it in cache, and returns it.

Examples

iex> ExMaps.get_distance_matrix([%{origins: ["Warsaw", "Kraków"], destinations: ["Amsterdam", "Utrecht"]}], language: "pl")
[%{"destination_addresses" => ...}]