mobilizon/lib/service/geospatial/provider.ex

78 lines
2.5 KiB
Elixir
Raw Normal View History

defmodule Mobilizon.Service.Geospatial.Provider do
@moduledoc """
Provider Behaviour for Geospatial stuff.
## Supported backends
* `Mobilizon.Service.Geospatial.Nominatim` [🔗](https://wiki.openstreetmap.org/wiki/Nominatim)
* `Mobilizon.Service.Geospatial.Photon` [🔗](https://photon.komoot.de)
* `Mobilizon.Service.Geospatial.Addok` [🔗](https://github.com/addok/addok)
* `Mobilizon.Service.Geospatial.MapQuest` [🔗](https://developer.mapquest.com/documentation/open/)
* `Mobilizon.Service.Geospatial.GoogleMaps` [🔗](https://developers.google.com/maps/documentation/geocoding/intro)
## Shared options
* `:user_agent` User-Agent string to send to the backend. Defaults to `"Mobilizon"`
2019-09-22 16:26:23 +02:00
* `:lang` Lang in which to prefer results. Used as a request parameter or
through an `Accept-Language` HTTP header. Defaults to `"en"`.
* `:country_code` An ISO 3166 country code. String or `nil`
2019-09-22 16:26:23 +02:00
* `:limit` Maximum limit for the number of results returned by the backend.
Defaults to `10`
* `:api_key` Allows to override the API key (if the backend requires one) set
inside the configuration.
* `:endpoint` Allows to override the endpoint set inside the configuration.
"""
alias Mobilizon.Addresses.Address
@doc """
Get an address from longitude and latitude coordinates.
## Options
Most backends implement all of [the shared options](#module-shared-options).
## Examples
iex> geocode(48.11, -1.77)
%Address{}
"""
2019-09-22 16:26:23 +02:00
@callback geocode(longitude :: number, latitude :: number, options :: keyword) :: [Address.t()]
@doc """
Search for an address
## Options
2019-09-22 16:26:23 +02:00
In addition to [the shared options](#module-shared-options), `c:search/2` also
accepts the following options:
2019-09-22 16:26:23 +02:00
* `coords` Map of coordinates (ex: `%{lon: 48.11, lat: -1.77}`) allowing to
give a geographic priority to the search. Defaults to `nil`.
## Examples
iex> search("10 rue Jangot")
%Address{}
"""
2019-09-22 16:26:23 +02:00
@callback search(address :: String.t(), options :: keyword) :: [Address.t()]
@doc """
Returns a `Geo.Point` for given coordinates
"""
2019-09-22 16:26:23 +02:00
@spec coordinates([number], number) :: Geo.Point.t()
def coordinates(coords, srid \\ 4326)
2019-09-22 16:26:23 +02:00
def coordinates([x, y], srid) when is_number(x) and is_number(y) do
%Geo.Point{coordinates: {x, y}, srid: srid}
end
2019-09-22 16:26:23 +02:00
def coordinates([x, y], srid) when is_bitstring(x) and is_bitstring(y) do
%Geo.Point{coordinates: {String.to_float(x), String.to_float(y)}, srid: srid}
end
2019-09-22 16:26:23 +02:00
@spec coordinates(any) :: nil
def coordinates(_, _), do: nil
end