forked from potsda.mn/mobilizon
Reuse existing addresses when creating an event
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
parent
ebf5534003
commit
0e0b68445b
|
@ -125,7 +125,8 @@ config :mobilizon, Mobilizon.Service.Geospatial.Photon,
|
||||||
endpoint: System.get_env("GEOSPATIAL_PHOTON_ENDPOINT") || "https://photon.komoot.de"
|
endpoint: System.get_env("GEOSPATIAL_PHOTON_ENDPOINT") || "https://photon.komoot.de"
|
||||||
|
|
||||||
config :mobilizon, Mobilizon.Service.Geospatial.GoogleMaps,
|
config :mobilizon, Mobilizon.Service.Geospatial.GoogleMaps,
|
||||||
api_key: System.get_env("GEOSPATIAL_GOOGLE_MAPS_API_KEY") || nil
|
api_key: System.get_env("GEOSPATIAL_GOOGLE_MAPS_API_KEY") || nil,
|
||||||
|
fetch_place_details: System.get_env("GEOSPATIAL_GOOGLE_MAPS_FETCH_PLACE_DETAILS") || true
|
||||||
|
|
||||||
config :mobilizon, Mobilizon.Service.Geospatial.MapQuest,
|
config :mobilizon, Mobilizon.Service.Geospatial.MapQuest,
|
||||||
api_key: System.get_env("GEOSPATIAL_MAP_QUEST_API_KEY") || nil
|
api_key: System.get_env("GEOSPATIAL_MAP_QUEST_API_KEY") || nil
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
<template>
|
<template>
|
||||||
|
<div>
|
||||||
<b-field label="Find an address">
|
<b-field label="Find an address">
|
||||||
<b-autocomplete
|
<b-autocomplete
|
||||||
:data="data"
|
:data="data"
|
||||||
|
v-model="queryText"
|
||||||
placeholder="e.g. 10 Rue Jangot"
|
placeholder="e.g. 10 Rue Jangot"
|
||||||
field="description"
|
field="description"
|
||||||
:loading="isFetching"
|
:loading="isFetching"
|
||||||
|
@ -9,45 +11,113 @@
|
||||||
@select="option => selected = option">
|
@select="option => selected = option">
|
||||||
|
|
||||||
<template slot-scope="{option}">
|
<template slot-scope="{option}">
|
||||||
<b>{{ option.description }}</b>
|
<b>{{ option.description }}</b><br />
|
||||||
|
<i v-if="option.url != null">Local</i>
|
||||||
<p>
|
<p>
|
||||||
<small>{{ option.street }}</small>, 
|
<small>{{ option.street }},  {{ option.postalCode }} {{ option.locality }}</small>
|
||||||
<small>{{ option.locality }}</small>
|
|
||||||
</p>
|
</p>
|
||||||
</template>
|
</template>
|
||||||
|
<template slot="empty">
|
||||||
|
<span v-if="queryText.length < 5">Please type at least 5 caracters</span>
|
||||||
|
<span v-else-if="isFetching">Searching…</span>
|
||||||
|
<div v-else class="is-enabled">
|
||||||
|
<span>No results for « {{ queryText }} »</span>
|
||||||
|
<p class="control" @click="addressModalActive = true">
|
||||||
|
<button type="button" class="button is-primary">Add</button>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
</b-autocomplete>
|
</b-autocomplete>
|
||||||
</b-field>
|
</b-field>
|
||||||
|
<b-modal :active.sync="addressModalActive" :width="640" has-modal-card scroll="keep">
|
||||||
|
<div class="modal-card" style="width: auto">
|
||||||
|
<header class="modal-card-head">
|
||||||
|
<p class="modal-card-title">Login</p>
|
||||||
|
</header>
|
||||||
|
<section class="modal-card-body">
|
||||||
|
<form>
|
||||||
|
<b-field :label="$gettext('Name')">
|
||||||
|
<b-input aria-required="true" required v-model="selected.description" />
|
||||||
|
</b-field>
|
||||||
|
|
||||||
|
<b-field :label="$gettext('Street')">
|
||||||
|
<b-input v-model="selected.street" />
|
||||||
|
</b-field>
|
||||||
|
|
||||||
|
<b-field :label="$gettext('Postal Code')">
|
||||||
|
<b-input v-model="selected.postalCode" />
|
||||||
|
</b-field>
|
||||||
|
|
||||||
|
<b-field :label="$gettext('Locality')">
|
||||||
|
<b-input v-model="selected.locality" />
|
||||||
|
</b-field>
|
||||||
|
|
||||||
|
<b-field :label="$gettext('Region')">
|
||||||
|
<b-input v-model="selected.region" />
|
||||||
|
</b-field>
|
||||||
|
|
||||||
|
<b-field :label="$gettext('Country')">
|
||||||
|
<b-input v-model="selected.country" />
|
||||||
|
</b-field>
|
||||||
|
</form>
|
||||||
|
</section>
|
||||||
|
<footer class="modal-card-foot">
|
||||||
|
<button class="button" type="button" @click="resetPopup()">Clear</button>
|
||||||
|
</footer>
|
||||||
|
</div>
|
||||||
|
</b-modal>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { Component, Prop, Vue, Watch } from 'vue-property-decorator';
|
import { Component, Prop, Vue, Watch } from 'vue-property-decorator';
|
||||||
import { IAddress } from '@/types/address.model';
|
import { Address, IAddress } from '@/types/address.model';
|
||||||
import { ADDRESS } from '@/graphql/address';
|
import { ADDRESS } from '@/graphql/address';
|
||||||
@Component
|
import { Modal } from 'buefy/dist/components/dialog';
|
||||||
|
@Component({
|
||||||
|
components: {
|
||||||
|
Modal,
|
||||||
|
},
|
||||||
|
})
|
||||||
export default class AddressAutoComplete extends Vue {
|
export default class AddressAutoComplete extends Vue {
|
||||||
|
|
||||||
@Prop({ required: false, default: () => [] }) initialData!: IAddress[];
|
@Prop({ required: false, default: () => [] }) initialData!: IAddress[];
|
||||||
|
|
||||||
data: IAddress[] = this.initialData;
|
data: IAddress[] = this.initialData;
|
||||||
selected: IAddress|null = null;
|
selected: IAddress|null = new Address();
|
||||||
isFetching: boolean = false;
|
isFetching: boolean = false;
|
||||||
|
queryText: string = '';
|
||||||
|
addressModalActive: boolean = false;
|
||||||
|
|
||||||
async getAsyncData(query) {
|
async getAsyncData(query) {
|
||||||
if (!query.length) {
|
if (query.length < 5) {
|
||||||
this.data = [];
|
this.data = [];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.isFetching = true;
|
this.isFetching = true;
|
||||||
const result = await this.$apollo.query({
|
const result = await this.$apollo.query({
|
||||||
query: ADDRESS,
|
query: ADDRESS,
|
||||||
|
fetchPolicy: 'no-cache',
|
||||||
variables: { query },
|
variables: { query },
|
||||||
});
|
});
|
||||||
|
|
||||||
this.data = result.data.searchAddress as IAddress[];
|
this.data = result.data.searchAddress as IAddress[];
|
||||||
|
this.isFetching = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Watch('selected')
|
// Watch deep because of subproperties
|
||||||
|
@Watch('selected', { deep: true })
|
||||||
updateSelected() {
|
updateSelected() {
|
||||||
this.$emit('input', this.selected);
|
this.$emit('input', this.selected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resetPopup() {
|
||||||
|
this.selected = new Address();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
<style lang="scss">
|
||||||
|
.autocomplete .dropdown-item.is-disabled .is-enabled {
|
||||||
|
opacity: 1 !important;
|
||||||
|
cursor: auto;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
|
@ -5,6 +5,7 @@ export const ADDRESS = gql`
|
||||||
searchAddress(
|
searchAddress(
|
||||||
query: $query
|
query: $query
|
||||||
) {
|
) {
|
||||||
|
id,
|
||||||
description,
|
description,
|
||||||
geom,
|
geom,
|
||||||
floor,
|
floor,
|
||||||
|
@ -12,7 +13,9 @@ export const ADDRESS = gql`
|
||||||
locality,
|
locality,
|
||||||
postalCode,
|
postalCode,
|
||||||
region,
|
region,
|
||||||
country
|
country,
|
||||||
|
url,
|
||||||
|
originId
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
|
@ -1,11 +1,23 @@
|
||||||
export interface IAddress {
|
export interface IAddress {
|
||||||
id: number;
|
id?: number;
|
||||||
description: string;
|
description: string;
|
||||||
floor: string;
|
floor: string;
|
||||||
street: string;
|
street: string;
|
||||||
locality: string;
|
locality: string;
|
||||||
postal_code: string;
|
postalCode: string;
|
||||||
region: string;
|
region: string;
|
||||||
country: string;
|
country: string;
|
||||||
geom: string;
|
geom?: string;
|
||||||
|
url?: string;
|
||||||
|
originId?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class Address implements IAddress {
|
||||||
|
country: string = '';
|
||||||
|
description: string = '';
|
||||||
|
floor: string = '';
|
||||||
|
locality: string = '';
|
||||||
|
postalCode: string = '';
|
||||||
|
region: string = '';
|
||||||
|
street: string = '';
|
||||||
}
|
}
|
||||||
|
|
|
@ -119,7 +119,6 @@ export default class CreateEvent extends Vue {
|
||||||
createEvent(e: Event) {
|
createEvent(e: Event) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
|
|
||||||
if (this.event.uuid === '') {
|
if (this.event.uuid === '') {
|
||||||
console.log('event', this.event);
|
console.log('event', this.event);
|
||||||
this.$apollo
|
this.$apollo
|
||||||
|
|
|
@ -75,7 +75,7 @@
|
||||||
<address>
|
<address>
|
||||||
<span class="addressDescription">{{ event.physicalAddress.description }}</span>
|
<span class="addressDescription">{{ event.physicalAddress.description }}</span>
|
||||||
<span>{{ event.physicalAddress.floor }} {{ event.physicalAddress.street }}</span>
|
<span>{{ event.physicalAddress.floor }} {{ event.physicalAddress.street }}</span>
|
||||||
<span>{{ event.physicalAddress.postal_code }} {{ event.physicalAddress.locality }}</span>
|
<span>{{ event.physicalAddress.postalCode }} {{ event.physicalAddress.locality }}</span>
|
||||||
<!-- <span>{{ event.physicalAddress.region }} {{ event.physicalAddress.country }}</span>-->
|
<!-- <span>{{ event.physicalAddress.region }} {{ event.physicalAddress.country }}</span>-->
|
||||||
</address>
|
</address>
|
||||||
<span class="map-show-button" @click="showMap = !showMap" v-if="event.physicalAddress && event.physicalAddress.geom">
|
<span class="map-show-button" @click="showMap = !showMap" v-if="event.physicalAddress && event.physicalAddress.geom">
|
||||||
|
|
|
@ -79,7 +79,7 @@ export default class CreateGroup extends Vue {
|
||||||
country: addressData.country,
|
country: addressData.country,
|
||||||
locality: addressData.city,
|
locality: addressData.city,
|
||||||
region: addressData.administrative_area_level_1,
|
region: addressData.administrative_area_level_1,
|
||||||
postal_code: addressData.postal_code,
|
postalCode: addressData.postalCode,
|
||||||
street: `${addressData.street_number} ${addressData.route}`,
|
street: `${addressData.street_number} ${addressData.route}`,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,8 @@ defmodule Mobilizon.Addresses.Address do
|
||||||
:region,
|
:region,
|
||||||
:postal_code,
|
:postal_code,
|
||||||
:street,
|
:street,
|
||||||
:url
|
:url,
|
||||||
|
:origin_id
|
||||||
]
|
]
|
||||||
@required [
|
@required [
|
||||||
:url
|
:url
|
||||||
|
@ -31,6 +32,7 @@ defmodule Mobilizon.Addresses.Address do
|
||||||
field(:postal_code, :string)
|
field(:postal_code, :string)
|
||||||
field(:street, :string)
|
field(:street, :string)
|
||||||
field(:url, :string)
|
field(:url, :string)
|
||||||
|
field(:origin_id, :string)
|
||||||
has_many(:event, Event, foreign_key: :physical_address_id)
|
has_many(:event, Event, foreign_key: :physical_address_id)
|
||||||
|
|
||||||
timestamps()
|
timestamps()
|
||||||
|
|
|
@ -50,6 +50,8 @@ defmodule Mobilizon.Addresses do
|
||||||
"""
|
"""
|
||||||
def get_address!(id), do: Repo.get!(Address, id)
|
def get_address!(id), do: Repo.get!(Address, id)
|
||||||
|
|
||||||
|
def get_address(id), do: Repo.get(Address, id)
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Gets a single address by it's url
|
Gets a single address by it's url
|
||||||
|
|
||||||
|
@ -80,7 +82,10 @@ defmodule Mobilizon.Addresses do
|
||||||
def create_address(attrs \\ %{}) do
|
def create_address(attrs \\ %{}) do
|
||||||
%Address{}
|
%Address{}
|
||||||
|> Address.changeset(attrs)
|
|> Address.changeset(attrs)
|
||||||
|> Repo.insert()
|
|> Repo.insert(
|
||||||
|
on_conflict: :replace_all_except_primary_key,
|
||||||
|
conflict_target: [:origin_id]
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
|
|
|
@ -20,6 +20,18 @@ defmodule MobilizonWeb.Resolvers.Address do
|
||||||
|
|
||||||
addresses = Task.await(local_addresses) ++ Task.await(remote_addresses)
|
addresses = Task.await(local_addresses) ++ Task.await(remote_addresses)
|
||||||
|
|
||||||
|
# If we have results with same origin_id than those locally saved, don't return them
|
||||||
|
addresses =
|
||||||
|
Enum.reduce(addresses, %{}, fn address, addresses ->
|
||||||
|
if Map.has_key?(addresses, address.origin_id) && !is_nil(address.url) do
|
||||||
|
addresses
|
||||||
|
else
|
||||||
|
Map.put(addresses, address.origin_id, address)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
addresses = Map.values(addresses)
|
||||||
|
|
||||||
{:ok, addresses}
|
{:ok, addresses}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -208,20 +208,21 @@ defmodule MobilizonWeb.Resolvers.Event do
|
||||||
defp save_attached_picture(args), do: {:ok, args}
|
defp save_attached_picture(args), do: {:ok, args}
|
||||||
|
|
||||||
@spec save_physical_address(map()) :: {:ok, map()}
|
@spec save_physical_address(map()) :: {:ok, map()}
|
||||||
defp save_physical_address(%{physical_address: %{url: physical_address_url}} = args) do
|
defp save_physical_address(%{physical_address: %{url: physical_address_url}} = args)
|
||||||
|
when not is_nil(physical_address_url) do
|
||||||
with %Address{} = address <- Addresses.get_address_by_url(physical_address_url),
|
with %Address{} = address <- Addresses.get_address_by_url(physical_address_url),
|
||||||
args <- Map.put(args, :physical_address, address) do
|
args <- Map.put(args, :physical_address, address.url) do
|
||||||
{:ok, args}
|
{:ok, args}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# @spec save_physical_address(map()) :: {:ok, map()}
|
@spec save_physical_address(map()) :: {:ok, map()}
|
||||||
# defp save_physical_address(%{physical_address: address} = args) do
|
defp save_physical_address(%{physical_address: address} = args) do
|
||||||
# with {:ok, %Address{} = address} <- Addresses.create_address(address),
|
with {:ok, %Address{} = address} <- Addresses.create_address(address),
|
||||||
# args <- Map.put(args, :physical_address, address) do
|
args <- Map.put(args, :physical_address, address.url) do
|
||||||
# {:ok, args}
|
{:ok, args}
|
||||||
# end
|
end
|
||||||
# end
|
end
|
||||||
|
|
||||||
@spec save_physical_address(map()) :: {:ok, map()}
|
@spec save_physical_address(map()) :: {:ok, map()}
|
||||||
defp save_physical_address(args), do: {:ok, args}
|
defp save_physical_address(args), do: {:ok, args}
|
||||||
|
|
|
@ -15,6 +15,8 @@ defmodule MobilizonWeb.Schema.AddressType do
|
||||||
field(:country, :string)
|
field(:country, :string)
|
||||||
field(:description, :string)
|
field(:description, :string)
|
||||||
field(:url, :string)
|
field(:url, :string)
|
||||||
|
field(:id, :integer)
|
||||||
|
field(:origin_id, :string)
|
||||||
end
|
end
|
||||||
|
|
||||||
object :phone_address do
|
object :phone_address do
|
||||||
|
@ -38,6 +40,8 @@ defmodule MobilizonWeb.Schema.AddressType do
|
||||||
field(:country, :string)
|
field(:country, :string)
|
||||||
field(:description, :string)
|
field(:description, :string)
|
||||||
field(:url, :string)
|
field(:url, :string)
|
||||||
|
field(:id, :integer)
|
||||||
|
field(:origin_id, :string)
|
||||||
end
|
end
|
||||||
|
|
||||||
object :address_queries do
|
object :address_queries do
|
||||||
|
|
|
@ -69,6 +69,10 @@ defmodule Mobilizon.Service.ActivityPub.Converters.Event do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp get_address(address_url) when is_bitstring(address_url) do
|
||||||
|
get_address(%{"id" => address_url})
|
||||||
|
end
|
||||||
|
|
||||||
defp get_address(%{"id" => url} = map) when is_map(map) and is_binary(url) do
|
defp get_address(%{"id" => url} = map) when is_map(map) and is_binary(url) do
|
||||||
Logger.debug("Address with an URL, let's check against our own database")
|
Logger.debug("Address with an URL, let's check against our own database")
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@ defmodule Mobilizon.Service.ActivityPub.Utils do
|
||||||
"""
|
"""
|
||||||
|
|
||||||
alias Mobilizon.Repo
|
alias Mobilizon.Repo
|
||||||
|
alias Mobilizon.Addresses
|
||||||
alias Mobilizon.Addresses.Address
|
alias Mobilizon.Addresses.Address
|
||||||
alias Mobilizon.Actors
|
alias Mobilizon.Actors
|
||||||
alias Mobilizon.Actors.Actor
|
alias Mobilizon.Actors.Actor
|
||||||
|
@ -301,37 +302,44 @@ defmodule Mobilizon.Service.ActivityPub.Utils do
|
||||||
end
|
end
|
||||||
|
|
||||||
def make_address_data(%Address{} = address) do
|
def make_address_data(%Address{} = address) do
|
||||||
res = %{
|
# res = %{
|
||||||
"type" => "Place",
|
# "type" => "Place",
|
||||||
"name" => address.description,
|
# "name" => address.description,
|
||||||
"id" => address.url,
|
# "id" => address.url,
|
||||||
"address" => %{
|
# "address" => %{
|
||||||
"type" => "PostalAddress",
|
# "type" => "PostalAddress",
|
||||||
"streetAddress" => address.street,
|
# "streetAddress" => address.street,
|
||||||
"postalCode" => address.postal_code,
|
# "postalCode" => address.postal_code,
|
||||||
"addressLocality" => address.locality,
|
# "addressLocality" => address.locality,
|
||||||
"addressRegion" => address.region,
|
# "addressRegion" => address.region,
|
||||||
"addressCountry" => address.country
|
# "addressCountry" => address.country
|
||||||
}
|
# }
|
||||||
}
|
# }
|
||||||
|
#
|
||||||
if is_nil(address.geom) do
|
# if is_nil(address.geom) do
|
||||||
res
|
# res
|
||||||
else
|
# else
|
||||||
Map.put(res, "geo", %{
|
# Map.put(res, "geo", %{
|
||||||
"type" => "GeoCoordinates",
|
# "type" => "GeoCoordinates",
|
||||||
"latitude" => address.geom.coordinates |> elem(0),
|
# "latitude" => address.geom.coordinates |> elem(0),
|
||||||
"longitude" => address.geom.coordinates |> elem(1)
|
# "longitude" => address.geom.coordinates |> elem(1)
|
||||||
})
|
# })
|
||||||
end
|
# end
|
||||||
|
address.url
|
||||||
end
|
end
|
||||||
|
|
||||||
def make_address_data(address) do
|
def make_address_data(address) when is_map(address) do
|
||||||
Address
|
Address
|
||||||
|> struct(address)
|
|> struct(address)
|
||||||
|> make_address_data()
|
|> make_address_data()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def make_address_data(address_url) when is_bitstring(address_url) do
|
||||||
|
with %Address{} = address <- Addresses.get_address_by_url(address_url) do
|
||||||
|
address.url
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Make an AP comment object from an set of values
|
Make an AP comment object from an set of values
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -12,6 +12,9 @@ defmodule Mobilizon.Service.Geospatial.GoogleMaps do
|
||||||
|
|
||||||
@api_key Application.get_env(:mobilizon, __MODULE__) |> get_in([:api_key])
|
@api_key Application.get_env(:mobilizon, __MODULE__) |> get_in([:api_key])
|
||||||
|
|
||||||
|
@fetch_place_details (Application.get_env(:mobilizon, __MODULE__)
|
||||||
|
|> get_in([:fetch_place_details])) in [true, "true", "True"]
|
||||||
|
|
||||||
@components [
|
@components [
|
||||||
"street_number",
|
"street_number",
|
||||||
"route",
|
"route",
|
||||||
|
@ -36,7 +39,7 @@ defmodule Mobilizon.Service.Geospatial.GoogleMaps do
|
||||||
with {:ok, %HTTPoison.Response{status_code: 200, body: body}} <-
|
with {:ok, %HTTPoison.Response{status_code: 200, body: body}} <-
|
||||||
HTTPoison.get(url),
|
HTTPoison.get(url),
|
||||||
{:ok, %{"results" => results, "status" => "OK"}} <- Poison.decode(body) do
|
{:ok, %{"results" => results, "status" => "OK"}} <- Poison.decode(body) do
|
||||||
Enum.map(results, &process_data/1)
|
Enum.map(results, fn entry -> process_data(entry, options) end)
|
||||||
else
|
else
|
||||||
{:ok, %{"status" => "REQUEST_DENIED", "error_message" => error_message}} ->
|
{:ok, %{"status" => "REQUEST_DENIED", "error_message" => error_message}} ->
|
||||||
raise ArgumentError, message: to_string(error_message)
|
raise ArgumentError, message: to_string(error_message)
|
||||||
|
@ -56,10 +59,13 @@ defmodule Mobilizon.Service.Geospatial.GoogleMaps do
|
||||||
with {:ok, %HTTPoison.Response{status_code: 200, body: body}} <-
|
with {:ok, %HTTPoison.Response{status_code: 200, body: body}} <-
|
||||||
HTTPoison.get(url),
|
HTTPoison.get(url),
|
||||||
{:ok, %{"results" => results, "status" => "OK"}} <- Poison.decode(body) do
|
{:ok, %{"results" => results, "status" => "OK"}} <- Poison.decode(body) do
|
||||||
Enum.map(results, fn entry -> process_data(entry) end)
|
results |> Enum.map(fn entry -> process_data(entry, options) end)
|
||||||
else
|
else
|
||||||
{:ok, %{"status" => "REQUEST_DENIED", "error_message" => error_message}} ->
|
{:ok, %{"status" => "REQUEST_DENIED", "error_message" => error_message}} ->
|
||||||
raise ArgumentError, message: to_string(error_message)
|
raise ArgumentError, message: to_string(error_message)
|
||||||
|
|
||||||
|
{:ok, %{"results" => [], "status" => "ZERO_RESULTS"}} ->
|
||||||
|
[]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -75,26 +81,45 @@ defmodule Mobilizon.Service.Geospatial.GoogleMaps do
|
||||||
lang
|
lang
|
||||||
}"
|
}"
|
||||||
|
|
||||||
|
uri =
|
||||||
case method do
|
case method do
|
||||||
:search ->
|
:search ->
|
||||||
url <> "&address=#{URI.encode(args.q)}"
|
url <> "&address=#{args.q}"
|
||||||
|
|
||||||
:geocode ->
|
:geocode ->
|
||||||
url <> "&latlng=#{args.lat},#{args.lon}"
|
url <> "&latlng=#{args.lat},#{args.lon}&result_type=street_address"
|
||||||
end
|
|
||||||
|
:place_details ->
|
||||||
|
"https://maps.googleapis.com/maps/api/place/details/json?key=#{api_key}&placeid=#{
|
||||||
|
args.place_id
|
||||||
|
}"
|
||||||
end
|
end
|
||||||
|
|
||||||
defp process_data(%{
|
URI.encode(uri)
|
||||||
|
end
|
||||||
|
|
||||||
|
defp process_data(
|
||||||
|
%{
|
||||||
"formatted_address" => description,
|
"formatted_address" => description,
|
||||||
"geometry" => %{"location" => %{"lat" => lat, "lng" => lon}},
|
"geometry" => %{"location" => %{"lat" => lat, "lng" => lon}},
|
||||||
"address_components" => components
|
"address_components" => components,
|
||||||
}) do
|
"place_id" => place_id
|
||||||
|
},
|
||||||
|
options
|
||||||
|
) do
|
||||||
components =
|
components =
|
||||||
@components
|
@components
|
||||||
|> Enum.reduce(%{}, fn component, acc ->
|
|> Enum.reduce(%{}, fn component, acc ->
|
||||||
Map.put(acc, component, extract_component(components, component))
|
Map.put(acc, component, extract_component(components, component))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
description =
|
||||||
|
if Keyword.get(options, :fetch_place_details, @fetch_place_details) == true do
|
||||||
|
do_fetch_place_details(place_id, options) || description
|
||||||
|
else
|
||||||
|
description
|
||||||
|
end
|
||||||
|
|
||||||
%Address{
|
%Address{
|
||||||
country: Map.get(components, "country"),
|
country: Map.get(components, "country"),
|
||||||
locality: Map.get(components, "locality"),
|
locality: Map.get(components, "locality"),
|
||||||
|
@ -103,7 +128,8 @@ defmodule Mobilizon.Service.Geospatial.GoogleMaps do
|
||||||
floor: nil,
|
floor: nil,
|
||||||
geom: [lon, lat] |> Provider.coordinates(),
|
geom: [lon, lat] |> Provider.coordinates(),
|
||||||
postal_code: Map.get(components, "postal_code"),
|
postal_code: Map.get(components, "postal_code"),
|
||||||
street: street_address(components)
|
street: street_address(components),
|
||||||
|
origin_id: "gm:" <> to_string(place_id)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -123,4 +149,25 @@ defmodule Mobilizon.Service.Geospatial.GoogleMaps do
|
||||||
Map.get(body, "route")
|
Map.get(body, "route")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp do_fetch_place_details(place_id, options) do
|
||||||
|
url = build_url(:place_details, %{place_id: place_id}, options)
|
||||||
|
|
||||||
|
Logger.debug("Asking Google Maps for details with #{url}")
|
||||||
|
|
||||||
|
with {:ok, %HTTPoison.Response{status_code: 200, body: body}} <-
|
||||||
|
HTTPoison.get(url),
|
||||||
|
{:ok, %{"result" => %{"name" => name}, "status" => "OK"}} <- Poison.decode(body) do
|
||||||
|
name
|
||||||
|
else
|
||||||
|
{:ok, %{"status" => "REQUEST_DENIED", "error_message" => error_message}} ->
|
||||||
|
raise ArgumentError, message: to_string(error_message)
|
||||||
|
|
||||||
|
{:ok, %{"status" => "INVALID_REQUEST"}} ->
|
||||||
|
raise ArgumentError, message: "Invalid Request"
|
||||||
|
|
||||||
|
{:ok, %{"results" => [], "status" => "ZERO_RESULTS"}} ->
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -39,7 +39,7 @@ defmodule Mobilizon.Service.Geospatial.Nominatim do
|
||||||
with {:ok, %HTTPoison.Response{status_code: 200, body: body}} <-
|
with {:ok, %HTTPoison.Response{status_code: 200, body: body}} <-
|
||||||
HTTPoison.get(url),
|
HTTPoison.get(url),
|
||||||
{:ok, body} <- Poison.decode(body) do
|
{:ok, body} <- Poison.decode(body) do
|
||||||
Enum.map(body, fn entry -> process_data(entry) end)
|
body |> Enum.map(fn entry -> process_data(entry) end) |> Enum.filter(& &1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -66,24 +66,63 @@ defmodule Mobilizon.Service.Geospatial.Nominatim do
|
||||||
|
|
||||||
@spec process_data(map()) :: Address.t()
|
@spec process_data(map()) :: Address.t()
|
||||||
defp process_data(%{"address" => address} = body) do
|
defp process_data(%{"address" => address} = body) do
|
||||||
|
try do
|
||||||
%Address{
|
%Address{
|
||||||
country: Map.get(address, "country"),
|
country: Map.get(address, "country"),
|
||||||
locality: Map.get(address, "city"),
|
locality: Map.get(address, "city"),
|
||||||
region: Map.get(address, "state"),
|
region: Map.get(address, "state"),
|
||||||
description: Map.get(body, "display_name"),
|
description: description(body),
|
||||||
floor: Map.get(address, "floor"),
|
floor: Map.get(address, "floor"),
|
||||||
geom: [Map.get(body, "lon"), Map.get(body, "lat")] |> Provider.coordinates(),
|
geom: [Map.get(body, "lon"), Map.get(body, "lat")] |> Provider.coordinates(),
|
||||||
postal_code: Map.get(address, "postcode"),
|
postal_code: Map.get(address, "postcode"),
|
||||||
street: street_address(address)
|
street: street_address(address),
|
||||||
|
origin_id: "osm:" <> to_string(Map.get(body, "osm_id"))
|
||||||
}
|
}
|
||||||
|
rescue
|
||||||
|
e in ArgumentError ->
|
||||||
|
Logger.warn(inspect(e))
|
||||||
|
nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec street_address(map()) :: String.t()
|
@spec street_address(map()) :: String.t()
|
||||||
defp street_address(body) do
|
defp street_address(body) do
|
||||||
if Map.has_key?(body, "house_number") do
|
road =
|
||||||
Map.get(body, "house_number") <> " " <> Map.get(body, "road")
|
cond do
|
||||||
else
|
Map.has_key?(body, "road") ->
|
||||||
Map.get(body, "road")
|
Map.get(body, "road")
|
||||||
|
|
||||||
|
Map.has_key?(body, "road") ->
|
||||||
|
Map.get(body, "road")
|
||||||
|
|
||||||
|
Map.has_key?(body, "pedestrian") ->
|
||||||
|
Map.get(body, "pedestrian")
|
||||||
|
|
||||||
|
true ->
|
||||||
|
""
|
||||||
|
end
|
||||||
|
|
||||||
|
Map.get(body, "house_number", "") <> " " <> road
|
||||||
|
end
|
||||||
|
|
||||||
|
@address29_classes ["amenity", "shop", "tourism", "leisure"]
|
||||||
|
@address29_categories ["office"]
|
||||||
|
|
||||||
|
@spec description(map()) :: String.t()
|
||||||
|
defp description(body) do
|
||||||
|
if !Map.has_key?(body, "display_name") do
|
||||||
|
Logger.warn("Address has no display name")
|
||||||
|
raise ArgumentError, message: "Address has no display_name"
|
||||||
|
end
|
||||||
|
|
||||||
|
description = Map.get(body, "display_name")
|
||||||
|
address = Map.get(body, "address")
|
||||||
|
|
||||||
|
if (Map.get(body, "category") in @address29_categories or
|
||||||
|
Map.get(body, "class") in @address29_classes) and Map.has_key?(address, "address29") do
|
||||||
|
Map.get(address, "address29")
|
||||||
|
else
|
||||||
|
description
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
defmodule Mobilizon.Repo.Migrations.AddOriginIdToAddresses do
|
||||||
|
use Ecto.Migration
|
||||||
|
|
||||||
|
def change do
|
||||||
|
alter table(:addresses) do
|
||||||
|
add(:origin_id, :string)
|
||||||
|
end
|
||||||
|
|
||||||
|
create(index(:addresses, [:origin_id], unique: true))
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,5 +1,5 @@
|
||||||
# source: http://localhost:4000/api
|
# source: http://localhost:4000/api
|
||||||
# timestamp: Wed Aug 21 2019 09:02:13 GMT+0200 (GMT+02:00)
|
# timestamp: Thu Aug 22 2019 12:34:52 GMT+0200 (GMT+02:00)
|
||||||
|
|
||||||
schema {
|
schema {
|
||||||
query: RootQueryType
|
query: RootQueryType
|
||||||
|
@ -111,9 +111,11 @@ type Address {
|
||||||
|
|
||||||
"""The geocoordinates for the point where this address is"""
|
"""The geocoordinates for the point where this address is"""
|
||||||
geom: Point
|
geom: Point
|
||||||
|
id: Int
|
||||||
|
|
||||||
"""The address's locality"""
|
"""The address's locality"""
|
||||||
locality: String
|
locality: String
|
||||||
|
originId: String
|
||||||
postalCode: String
|
postalCode: String
|
||||||
region: String
|
region: String
|
||||||
|
|
||||||
|
@ -131,9 +133,11 @@ input AddressInput {
|
||||||
|
|
||||||
"""The geocoordinates for the point where this address is"""
|
"""The geocoordinates for the point where this address is"""
|
||||||
geom: Point
|
geom: Point
|
||||||
|
id: Int
|
||||||
|
|
||||||
"""The address's locality"""
|
"""The address's locality"""
|
||||||
locality: String
|
locality: String
|
||||||
|
originId: String
|
||||||
postalCode: String
|
postalCode: String
|
||||||
region: String
|
region: String
|
||||||
|
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -6,23 +6,22 @@
|
||||||
"method": "get",
|
"method": "get",
|
||||||
"options": [],
|
"options": [],
|
||||||
"request_body": "",
|
"request_body": "",
|
||||||
"url": "https://maps.googleapis.com/maps/api/geocode/json?address=10%20rue%20Jangot&limit=10&key=toto&language=en"
|
"url": "https://maps.googleapis.com/maps/api/geocode/json?limit=10&key=toto&language=en&address=10%20rue%20Jangot"
|
||||||
},
|
},
|
||||||
"response": {
|
"response": {
|
||||||
"binary": false,
|
"binary": false,
|
||||||
"body": "{\n \"results\" : [\n {\n \"address_components\" : [\n {\n \"long_name\" : \"10\",\n \"short_name\" : \"10\",\n \"types\" : [ \"street_number\" ]\n },\n {\n \"long_name\" : \"Rue Jangot\",\n \"short_name\" : \"Rue Jangot\",\n \"types\" : [ \"route\" ]\n },\n {\n \"long_name\" : \"Lyon\",\n \"short_name\" : \"Lyon\",\n \"types\" : [ \"locality\", \"political\" ]\n },\n {\n \"long_name\" : \"Rhône\",\n \"short_name\" : \"Rhône\",\n \"types\" : [ \"administrative_area_level_2\", \"political\" ]\n },\n {\n \"long_name\" : \"Auvergne-Rhône-Alpes\",\n \"short_name\" : \"Auvergne-Rhône-Alpes\",\n \"types\" : [ \"administrative_area_level_1\", \"political\" ]\n },\n {\n \"long_name\" : \"France\",\n \"short_name\" : \"FR\",\n \"types\" : [ \"country\", \"political\" ]\n },\n {\n \"long_name\" : \"69007\",\n \"short_name\" : \"69007\",\n \"types\" : [ \"postal_code\" ]\n }\n ],\n \"formatted_address\" : \"10 Rue Jangot, 69007 Lyon, France\",\n \"geometry\" : {\n \"location\" : {\n \"lat\" : 45.75164940000001,\n \"lng\" : 4.8424032\n },\n \"location_type\" : \"ROOFTOP\",\n \"viewport\" : {\n \"northeast\" : {\n \"lat\" : 45.75299838029151,\n \"lng\" : 4.843752180291502\n },\n \"southwest\" : {\n \"lat\" : 45.75030041970851,\n \"lng\" : 4.841054219708497\n }\n }\n },\n \"place_id\" : \"ChIJtW0QikTq9EcRLI4Vy6bRx0U\",\n \"plus_code\" : {\n \"compound_code\" : \"QR2R+MX Lyon, France\",\n \"global_code\" : \"8FQ6QR2R+MX\"\n },\n \"types\" : [ \"street_address\" ]\n }\n ],\n \"status\" : \"OK\"\n}\n",
|
"body": "{\n \"results\" : [\n {\n \"address_components\" : [\n {\n \"long_name\" : \"10\",\n \"short_name\" : \"10\",\n \"types\" : [ \"street_number\" ]\n },\n {\n \"long_name\" : \"Rue Jangot\",\n \"short_name\" : \"Rue Jangot\",\n \"types\" : [ \"route\" ]\n },\n {\n \"long_name\" : \"Lyon\",\n \"short_name\" : \"Lyon\",\n \"types\" : [ \"locality\", \"political\" ]\n },\n {\n \"long_name\" : \"Rhône\",\n \"short_name\" : \"Rhône\",\n \"types\" : [ \"administrative_area_level_2\", \"political\" ]\n },\n {\n \"long_name\" : \"Auvergne-Rhône-Alpes\",\n \"short_name\" : \"Auvergne-Rhône-Alpes\",\n \"types\" : [ \"administrative_area_level_1\", \"political\" ]\n },\n {\n \"long_name\" : \"France\",\n \"short_name\" : \"FR\",\n \"types\" : [ \"country\", \"political\" ]\n },\n {\n \"long_name\" : \"69007\",\n \"short_name\" : \"69007\",\n \"types\" : [ \"postal_code\" ]\n }\n ],\n \"formatted_address\" : \"10 Rue Jangot, 69007 Lyon, France\",\n \"geometry\" : {\n \"location\" : {\n \"lat\" : 45.75164940000001,\n \"lng\" : 4.8424032\n },\n \"location_type\" : \"ROOFTOP\",\n \"viewport\" : {\n \"northeast\" : {\n \"lat\" : 45.75299838029151,\n \"lng\" : 4.843752180291502\n },\n \"southwest\" : {\n \"lat\" : 45.75030041970851,\n \"lng\" : 4.841054219708497\n }\n }\n },\n \"place_id\" : \"ChIJtW0QikTq9EcRLI4Vy6bRx0U\",\n \"plus_code\" : {\n \"compound_code\" : \"QR2R+MX Lyon, France\",\n \"global_code\" : \"8FQ6QR2R+MX\"\n },\n \"types\" : [ \"street_address\" ]\n }\n ],\n \"status\" : \"OK\"\n}\n",
|
||||||
"headers": {
|
"headers": {
|
||||||
"Content-Type": "application/json; charset=UTF-8",
|
"Content-Type": "application/json; charset=UTF-8",
|
||||||
"Date": "Wed, 13 Mar 2019 17:50:19 GMT",
|
"Date": "Thu, 22 Aug 2019 13:05:39 GMT",
|
||||||
"Expires": "Thu, 14 Mar 2019 17:50:19 GMT",
|
"Expires": "Thu, 22 Aug 2019 13:06:09 GMT",
|
||||||
|
"Cache-Control": "public, max-age=30",
|
||||||
"Access-Control-Allow-Origin": "*",
|
"Access-Control-Allow-Origin": "*",
|
||||||
"Server": "mafe",
|
"Server": "mafe",
|
||||||
"X-XSS-Protection": "1; mode=block",
|
"X-XSS-Protection": "0",
|
||||||
"X-Frame-Options": "SAMEORIGIN",
|
"X-Frame-Options": "SAMEORIGIN",
|
||||||
"Server-Timing": "gfet4t7; dur=52",
|
"Server-Timing": "gfet4t7; dur=44",
|
||||||
"Cache-Control": "public, max-age=86400",
|
"Alt-Svc": "quic=\":443\"; ma=2592000; v=\"46,43,39\"",
|
||||||
"Age": "17",
|
|
||||||
"Alt-Svc": "quic=\":443\"; ma=2592000; v=\"46,44,43,39\"",
|
|
||||||
"Accept-Ranges": "none",
|
"Accept-Ranges": "none",
|
||||||
"Vary": "Accept-Encoding",
|
"Vary": "Accept-Encoding",
|
||||||
"Transfer-Encoding": "chunked"
|
"Transfer-Encoding": "chunked"
|
||||||
|
@ -30,5 +29,35 @@
|
||||||
"status_code": 200,
|
"status_code": 200,
|
||||||
"type": "ok"
|
"type": "ok"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"request": {
|
||||||
|
"body": "",
|
||||||
|
"headers": [],
|
||||||
|
"method": "get",
|
||||||
|
"options": [],
|
||||||
|
"request_body": "",
|
||||||
|
"url": "https://maps.googleapis.com/maps/api/place/details/json?key=toto&placeid=ChIJtW0QikTq9EcRLI4Vy6bRx0U"
|
||||||
|
},
|
||||||
|
"response": {
|
||||||
|
"binary": false,
|
||||||
|
"body": "{\n \"html_attributions\" : [],\n \"result\" : {\n \"address_components\" : [\n {\n \"long_name\" : \"10\",\n \"short_name\" : \"10\",\n \"types\" : [ \"street_number\" ]\n },\n {\n \"long_name\" : \"Rue Jangot\",\n \"short_name\" : \"Rue Jangot\",\n \"types\" : [ \"route\" ]\n },\n {\n \"long_name\" : \"Lyon\",\n \"short_name\" : \"Lyon\",\n \"types\" : [ \"locality\", \"political\" ]\n },\n {\n \"long_name\" : \"Rhône\",\n \"short_name\" : \"Rhône\",\n \"types\" : [ \"administrative_area_level_2\", \"political\" ]\n },\n {\n \"long_name\" : \"Auvergne-Rhône-Alpes\",\n \"short_name\" : \"Auvergne-Rhône-Alpes\",\n \"types\" : [ \"administrative_area_level_1\", \"political\" ]\n },\n {\n \"long_name\" : \"France\",\n \"short_name\" : \"FR\",\n \"types\" : [ \"country\", \"political\" ]\n },\n {\n \"long_name\" : \"69007\",\n \"short_name\" : \"69007\",\n \"types\" : [ \"postal_code\" ]\n }\n ],\n \"adr_address\" : \"\\u003cspan class=\\\"street-address\\\"\\u003e10 Rue Jangot\\u003c/span\\u003e, \\u003cspan class=\\\"postal-code\\\"\\u003e69007\\u003c/span\\u003e \\u003cspan class=\\\"locality\\\"\\u003eLyon\\u003c/span\\u003e, \\u003cspan class=\\\"country-name\\\"\\u003eFrance\\u003c/span\\u003e\",\n \"formatted_address\" : \"10 Rue Jangot, 69007 Lyon, France\",\n \"geometry\" : {\n \"location\" : {\n \"lat\" : 45.75164940000001,\n \"lng\" : 4.842403200000001\n },\n \"viewport\" : {\n \"northeast\" : {\n \"lat\" : 45.7530412802915,\n \"lng\" : 4.843668630291503\n },\n \"southwest\" : {\n \"lat\" : 45.75034331970851,\n \"lng\" : 4.840970669708498\n }\n }\n },\n \"icon\" : \"https://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png\",\n \"id\" : \"61b9418d092d2ed05ddd65a55dddefda5b9628cc\",\n \"name\" : \"10 Rue Jangot\",\n \"place_id\" : \"ChIJtW0QikTq9EcRLI4Vy6bRx0U\",\n \"plus_code\" : {\n \"compound_code\" : \"QR2R+MX Lyon, France\",\n \"global_code\" : \"8FQ6QR2R+MX\"\n },\n \"reference\" : \"ChIJtW0QikTq9EcRLI4Vy6bRx0U\",\n \"scope\" : \"GOOGLE\",\n \"types\" : [ \"street_address\" ],\n \"url\" : \"https://maps.google.com/?q=10+Rue+Jangot,+69007+Lyon,+France&ftid=0x47f4ea448a106db5:0x45c7d1a6cb158e2c\",\n \"utc_offset\" : 120,\n \"vicinity\" : \"Lyon\"\n },\n \"status\" : \"OK\"\n}\n",
|
||||||
|
"headers": {
|
||||||
|
"Content-Type": "application/json; charset=UTF-8",
|
||||||
|
"Date": "Thu, 22 Aug 2019 13:05:39 GMT",
|
||||||
|
"Expires": "Thu, 22 Aug 2019 13:10:39 GMT",
|
||||||
|
"Cache-Control": "public, max-age=300",
|
||||||
|
"Server": "scaffolding on HTTPServer2",
|
||||||
|
"X-XSS-Protection": "0",
|
||||||
|
"X-Frame-Options": "SAMEORIGIN",
|
||||||
|
"Server-Timing": "gfet4t7; dur=86",
|
||||||
|
"Alt-Svc": "quic=\":443\"; ma=2592000; v=\"46,43,39\"",
|
||||||
|
"Accept-Ranges": "none",
|
||||||
|
"Vary": "Accept-Language,Accept-Encoding",
|
||||||
|
"Transfer-Encoding": "chunked"
|
||||||
|
},
|
||||||
|
"status_code": 200,
|
||||||
|
"type": "ok"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
|
@ -43,7 +43,7 @@ defmodule Mobilizon.Service.Geospatial.GoogleMapsTest do
|
||||||
use_cassette "geospatial/google_maps/search" do
|
use_cassette "geospatial/google_maps/search" do
|
||||||
assert %Address{
|
assert %Address{
|
||||||
locality: "Lyon",
|
locality: "Lyon",
|
||||||
description: "10 Rue Jangot, 69007 Lyon, France",
|
description: "10 Rue Jangot",
|
||||||
region: "Auvergne-Rhône-Alpes",
|
region: "Auvergne-Rhône-Alpes",
|
||||||
country: "France",
|
country: "France",
|
||||||
postal_code: "69007",
|
postal_code: "69007",
|
||||||
|
@ -52,8 +52,13 @@ defmodule Mobilizon.Service.Geospatial.GoogleMapsTest do
|
||||||
coordinates: {4.8424032, 45.75164940000001},
|
coordinates: {4.8424032, 45.75164940000001},
|
||||||
properties: %{},
|
properties: %{},
|
||||||
srid: 4326
|
srid: 4326
|
||||||
}
|
},
|
||||||
} == GoogleMaps.search("10 rue Jangot", api_key: "toto") |> hd
|
origin_id: "gm:ChIJtW0QikTq9EcRLI4Vy6bRx0U"
|
||||||
|
} ==
|
||||||
|
GoogleMaps.search("10 rue Jangot",
|
||||||
|
api_key: "toto"
|
||||||
|
)
|
||||||
|
|> hd
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -61,16 +66,17 @@ defmodule Mobilizon.Service.Geospatial.GoogleMapsTest do
|
||||||
use_cassette "geospatial/google_maps/geocode" do
|
use_cassette "geospatial/google_maps/geocode" do
|
||||||
assert %Address{
|
assert %Address{
|
||||||
locality: "Lyon",
|
locality: "Lyon",
|
||||||
description: "10 Rue Jangot, 69007 Lyon, France",
|
description: "10bis Rue Jangot",
|
||||||
region: "Auvergne-Rhône-Alpes",
|
region: "Auvergne-Rhône-Alpes",
|
||||||
country: "France",
|
country: "France",
|
||||||
postal_code: "69007",
|
postal_code: "69007",
|
||||||
street: "10 Rue Jangot",
|
street: "10bis Rue Jangot",
|
||||||
geom: %Geo.Point{
|
geom: %Geo.Point{
|
||||||
coordinates: {4.8424967, 45.751725},
|
coordinates: {4.8424966, 45.751725},
|
||||||
properties: %{},
|
properties: %{},
|
||||||
srid: 4326
|
srid: 4326
|
||||||
}
|
},
|
||||||
|
origin_id: "gm:ChIJrW0QikTq9EcR96jk2OnO75w"
|
||||||
} ==
|
} ==
|
||||||
GoogleMaps.geocode(4.842569, 45.751718, api_key: "toto")
|
GoogleMaps.geocode(4.842569, 45.751718, api_key: "toto")
|
||||||
|> hd
|
|> hd
|
||||||
|
|
|
@ -39,7 +39,8 @@ defmodule Mobilizon.Service.Geospatial.NominatimTest do
|
||||||
coordinates: {4.8425657, 45.7517141},
|
coordinates: {4.8425657, 45.7517141},
|
||||||
properties: %{},
|
properties: %{},
|
||||||
srid: 4326
|
srid: 4326
|
||||||
}
|
},
|
||||||
|
origin_id: "osm:3078260611"
|
||||||
} == Nominatim.search("10 rue Jangot") |> hd
|
} == Nominatim.search("10 rue Jangot") |> hd
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -58,7 +59,8 @@ defmodule Mobilizon.Service.Geospatial.NominatimTest do
|
||||||
coordinates: {4.8425657, 45.7517141},
|
coordinates: {4.8425657, 45.7517141},
|
||||||
properties: %{},
|
properties: %{},
|
||||||
srid: 4326
|
srid: 4326
|
||||||
}
|
},
|
||||||
|
origin_id: "osm:3078260611"
|
||||||
} ==
|
} ==
|
||||||
Nominatim.geocode(4.842569, 45.751718)
|
Nominatim.geocode(4.842569, 45.751718)
|
||||||
|> hd
|
|> hd
|
||||||
|
|
Loading…
Reference in a new issue