Skip to content

Elixir wrapper for Google Directions API. Can return the drive time and driving distance between two places.

License

Notifications You must be signed in to change notification settings

sinclair/distancex

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Distancex

Elixir-wrapper for Google Directions API. Can return the drive time and driving distance between two places.

A sample http request and the corresponding json response

Installation

Dependencies: Make sure you have Erlang 18+ version installed and Elixir 1.x version. This hex package will not work with Erlang 17.x version.

Add distancex to your list of dependencies in mix.exs:

def deps do
 [{:distancex, "~> 0.0.3"} ]
end

Install the package

mix deps.get

Config

#config.exs

config :distancex, api_key: "YourAPIKEY"

Usage

The origin and destinations can be either a place name or a combo of latitude and longitude.

$ iex -S mix
iex> Distancex.distance("Vancouver", "San Francisco")
#=> 1529113
iex> Distancex.duration("Vancouver", "San Francisco")
#=> 53750
iex> Distancex.distance("49.2827N,123.1207W", "7.7833N,122.4167W")
#=> 1529113
iex> Distancex.duration("49.2827N,123.1207W", "7.7833N,122.4167W")
#=> 53750
iex> Distancex.distance_time("49.2827N,123.1207W", "7.7833N,122.4167W")
#=> {1529113, 53750}
iex> Distancex.distance_time("Vancouver", "San Francisco")
#=> {1529113, 53750}

Invalid key

$ iex -S mix
iex> Distancex.distance("Vancouver", "San Francisco")
#=> {:error, "The provided API key is expired."}

"Everything we hear is an opinion, not a fact. Everything we see is a perspective, not the truth." ― Marcus Aurelius, Meditations

About

Elixir wrapper for Google Directions API. Can return the drive time and driving distance between two places.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Elixir 100.0%