Reuse existing addresses when creating an event

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2019-08-22 15:57:44 +02:00
parent ebf5534003
commit 0e0b68445b
No known key found for this signature in database
GPG Key ID: A061B9DDE0CA0773
22 changed files with 410 additions and 121 deletions

View File

@ -125,7 +125,8 @@ config :mobilizon, Mobilizon.Service.Geospatial.Photon,
endpoint: System.get_env("GEOSPATIAL_PHOTON_ENDPOINT") || "https://photon.komoot.de"
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,
api_key: System.get_env("GEOSPATIAL_MAP_QUEST_API_KEY") || nil

View File

@ -1,53 +1,123 @@
<template>
<b-field label="Find an address">
<b-autocomplete
:data="data"
placeholder="e.g. 10 Rue Jangot"
field="description"
:loading="isFetching"
@typing="getAsyncData"
@select="option => selected = option">
<div>
<b-field label="Find an address">
<b-autocomplete
:data="data"
v-model="queryText"
placeholder="e.g. 10 Rue Jangot"
field="description"
:loading="isFetching"
@typing="getAsyncData"
@select="option => selected = option">
<template slot-scope="{option}">
<b>{{ option.description }}</b>
<p>
<small>{{ option.street }}</small>,&#32;
<small>{{ option.locality }}</small>
</p>
</template>
</b-autocomplete>
</b-field>
<template slot-scope="{option}">
<b>{{ option.description }}</b><br />
<i v-if="option.url != null">Local</i>
<p>
<small>{{ option.street }},&#32; {{ option.postalCode }} {{ option.locality }}</small>
</p>
</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-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>
<script lang="ts">
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';
@Component
import { Modal } from 'buefy/dist/components/dialog';
@Component({
components: {
Modal,
},
})
export default class AddressAutoComplete extends Vue {
@Prop({ required: false, default: () => [] }) initialData!: IAddress[];
data: IAddress[] = this.initialData;
selected: IAddress|null = null;
selected: IAddress|null = new Address();
isFetching: boolean = false;
queryText: string = '';
addressModalActive: boolean = false;
async getAsyncData(query) {
if (!query.length) {
if (query.length < 5) {
this.data = [];
return;
}
this.isFetching = true;
const result = await this.$apollo.query({
query: ADDRESS,
fetchPolicy: 'no-cache',
variables: { query },
});
this.data = result.data.searchAddress as IAddress[];
this.isFetching = false;
}
@Watch('selected')
// Watch deep because of subproperties
@Watch('selected', { deep: true })
updateSelected() {
this.$emit('input', this.selected);
}
resetPopup() {
this.selected = new Address();
}
}
</script>
<style lang="scss">
.autocomplete .dropdown-item.is-disabled .is-enabled {
opacity: 1 !important;
cursor: auto;
}
</style>

View File

@ -5,6 +5,7 @@ export const ADDRESS = gql`
searchAddress(
query: $query
) {
id,
description,
geom,
floor,
@ -12,7 +13,9 @@ export const ADDRESS = gql`
locality,
postalCode,
region,
country
country,
url,
originId
}
}
`;

View File

@ -1,11 +1,23 @@
export interface IAddress {
id: number;
id?: number;
description: string;
floor: string;
street: string;
locality: string;
postal_code: string;
postalCode: string;
region: 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 = '';
}

View File

@ -119,7 +119,6 @@ export default class CreateEvent extends Vue {
createEvent(e: Event) {
e.preventDefault();
if (this.event.uuid === '') {
console.log('event', this.event);
this.$apollo

View File

@ -75,7 +75,7 @@
<address>
<span class="addressDescription">{{ event.physicalAddress.description }}</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>-->
</address>
<span class="map-show-button" @click="showMap = !showMap" v-if="event.physicalAddress && event.physicalAddress.geom">

View File

@ -79,7 +79,7 @@ export default class CreateGroup extends Vue {
country: addressData.country,
locality: addressData.city,
region: addressData.administrative_area_level_1,
postal_code: addressData.postal_code,
postalCode: addressData.postalCode,
street: `${addressData.street_number} ${addressData.route}`,
};
}

View File

@ -15,7 +15,8 @@ defmodule Mobilizon.Addresses.Address do
:region,
:postal_code,
:street,
:url
:url,
:origin_id
]
@required [
:url
@ -31,6 +32,7 @@ defmodule Mobilizon.Addresses.Address do
field(:postal_code, :string)
field(:street, :string)
field(:url, :string)
field(:origin_id, :string)
has_many(:event, Event, foreign_key: :physical_address_id)
timestamps()

View File

@ -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)
@doc """
Gets a single address by it's url
@ -80,7 +82,10 @@ defmodule Mobilizon.Addresses do
def create_address(attrs \\ %{}) do
%Address{}
|> Address.changeset(attrs)
|> Repo.insert()
|> Repo.insert(
on_conflict: :replace_all_except_primary_key,
conflict_target: [:origin_id]
)
end
@doc """

View File

@ -20,6 +20,18 @@ defmodule MobilizonWeb.Resolvers.Address do
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}
end

View File

@ -208,20 +208,21 @@ defmodule MobilizonWeb.Resolvers.Event do
defp save_attached_picture(args), do: {:ok, args}
@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),
args <- Map.put(args, :physical_address, address) do
args <- Map.put(args, :physical_address, address.url) do
{:ok, args}
end
end
# @spec save_physical_address(map()) :: {:ok, map()}
# defp save_physical_address(%{physical_address: address} = args) do
# with {:ok, %Address{} = address} <- Addresses.create_address(address),
# args <- Map.put(args, :physical_address, address) do
# {:ok, args}
# end
# end
@spec save_physical_address(map()) :: {:ok, map()}
defp save_physical_address(%{physical_address: address} = args) do
with {:ok, %Address{} = address} <- Addresses.create_address(address),
args <- Map.put(args, :physical_address, address.url) do
{:ok, args}
end
end
@spec save_physical_address(map()) :: {:ok, map()}
defp save_physical_address(args), do: {:ok, args}

View File

@ -15,6 +15,8 @@ defmodule MobilizonWeb.Schema.AddressType do
field(:country, :string)
field(:description, :string)
field(:url, :string)
field(:id, :integer)
field(:origin_id, :string)
end
object :phone_address do
@ -38,6 +40,8 @@ defmodule MobilizonWeb.Schema.AddressType do
field(:country, :string)
field(:description, :string)
field(:url, :string)
field(:id, :integer)
field(:origin_id, :string)
end
object :address_queries do

View File

@ -69,6 +69,10 @@ defmodule Mobilizon.Service.ActivityPub.Converters.Event do
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
Logger.debug("Address with an URL, let's check against our own database")

View File

@ -11,6 +11,7 @@ defmodule Mobilizon.Service.ActivityPub.Utils do
"""
alias Mobilizon.Repo
alias Mobilizon.Addresses
alias Mobilizon.Addresses.Address
alias Mobilizon.Actors
alias Mobilizon.Actors.Actor
@ -301,37 +302,44 @@ defmodule Mobilizon.Service.ActivityPub.Utils do
end
def make_address_data(%Address{} = address) do
res = %{
"type" => "Place",
"name" => address.description,
"id" => address.url,
"address" => %{
"type" => "PostalAddress",
"streetAddress" => address.street,
"postalCode" => address.postal_code,
"addressLocality" => address.locality,
"addressRegion" => address.region,
"addressCountry" => address.country
}
}
if is_nil(address.geom) do
res
else
Map.put(res, "geo", %{
"type" => "GeoCoordinates",
"latitude" => address.geom.coordinates |> elem(0),
"longitude" => address.geom.coordinates |> elem(1)
})
end
# res = %{
# "type" => "Place",
# "name" => address.description,
# "id" => address.url,
# "address" => %{
# "type" => "PostalAddress",
# "streetAddress" => address.street,
# "postalCode" => address.postal_code,
# "addressLocality" => address.locality,
# "addressRegion" => address.region,
# "addressCountry" => address.country
# }
# }
#
# if is_nil(address.geom) do
# res
# else
# Map.put(res, "geo", %{
# "type" => "GeoCoordinates",
# "latitude" => address.geom.coordinates |> elem(0),
# "longitude" => address.geom.coordinates |> elem(1)
# })
# end
address.url
end
def make_address_data(address) do
def make_address_data(address) when is_map(address) do
Address
|> struct(address)
|> make_address_data()
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 """
Make an AP comment object from an set of values
"""

View File

@ -12,6 +12,9 @@ defmodule Mobilizon.Service.Geospatial.GoogleMaps do
@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 [
"street_number",
"route",
@ -36,7 +39,7 @@ defmodule Mobilizon.Service.Geospatial.GoogleMaps do
with {:ok, %HTTPoison.Response{status_code: 200, body: body}} <-
HTTPoison.get(url),
{: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
{:ok, %{"status" => "REQUEST_DENIED", "error_message" => 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}} <-
HTTPoison.get(url),
{: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
{:ok, %{"status" => "REQUEST_DENIED", "error_message" => error_message}} ->
raise ArgumentError, message: to_string(error_message)
{:ok, %{"results" => [], "status" => "ZERO_RESULTS"}} ->
[]
end
end
@ -75,26 +81,45 @@ defmodule Mobilizon.Service.Geospatial.GoogleMaps do
lang
}"
case method do
:search ->
url <> "&address=#{URI.encode(args.q)}"
uri =
case method do
:search ->
url <> "&address=#{args.q}"
:geocode ->
url <> "&latlng=#{args.lat},#{args.lon}"
end
:geocode ->
url <> "&latlng=#{args.lat},#{args.lon}&result_type=street_address"
:place_details ->
"https://maps.googleapis.com/maps/api/place/details/json?key=#{api_key}&placeid=#{
args.place_id
}"
end
URI.encode(uri)
end
defp process_data(%{
"formatted_address" => description,
"geometry" => %{"location" => %{"lat" => lat, "lng" => lon}},
"address_components" => components
}) do
defp process_data(
%{
"formatted_address" => description,
"geometry" => %{"location" => %{"lat" => lat, "lng" => lon}},
"address_components" => components,
"place_id" => place_id
},
options
) do
components =
@components
|> Enum.reduce(%{}, fn component, acc ->
Map.put(acc, component, extract_component(components, component))
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{
country: Map.get(components, "country"),
locality: Map.get(components, "locality"),
@ -103,7 +128,8 @@ defmodule Mobilizon.Service.Geospatial.GoogleMaps do
floor: nil,
geom: [lon, lat] |> Provider.coordinates(),
postal_code: Map.get(components, "postal_code"),
street: street_address(components)
street: street_address(components),
origin_id: "gm:" <> to_string(place_id)
}
end
@ -123,4 +149,25 @@ defmodule Mobilizon.Service.Geospatial.GoogleMaps do
Map.get(body, "route")
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

View File

@ -39,7 +39,7 @@ defmodule Mobilizon.Service.Geospatial.Nominatim do
with {:ok, %HTTPoison.Response{status_code: 200, body: body}} <-
HTTPoison.get(url),
{: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
@ -66,24 +66,63 @@ defmodule Mobilizon.Service.Geospatial.Nominatim do
@spec process_data(map()) :: Address.t()
defp process_data(%{"address" => address} = body) do
%Address{
country: Map.get(address, "country"),
locality: Map.get(address, "city"),
region: Map.get(address, "state"),
description: Map.get(body, "display_name"),
floor: Map.get(address, "floor"),
geom: [Map.get(body, "lon"), Map.get(body, "lat")] |> Provider.coordinates(),
postal_code: Map.get(address, "postcode"),
street: street_address(address)
}
try do
%Address{
country: Map.get(address, "country"),
locality: Map.get(address, "city"),
region: Map.get(address, "state"),
description: description(body),
floor: Map.get(address, "floor"),
geom: [Map.get(body, "lon"), Map.get(body, "lat")] |> Provider.coordinates(),
postal_code: Map.get(address, "postcode"),
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
@spec street_address(map()) :: String.t()
defp street_address(body) do
if Map.has_key?(body, "house_number") do
Map.get(body, "house_number") <> " " <> Map.get(body, "road")
road =
cond do
Map.has_key?(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
Map.get(body, "road")
description
end
end
end

View File

@ -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

View File

@ -1,5 +1,5 @@
# 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 {
query: RootQueryType
@ -111,9 +111,11 @@ type Address {
"""The geocoordinates for the point where this address is"""
geom: Point
id: Int
"""The address's locality"""
locality: String
originId: String
postalCode: String
region: String
@ -131,9 +133,11 @@ input AddressInput {
"""The geocoordinates for the point where this address is"""
geom: Point
id: Int
"""The address's locality"""
locality: String
originId: String
postalCode: String
region: String

File diff suppressed because one or more lines are too long

View File

@ -6,23 +6,22 @@
"method": "get",
"options": [],
"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": {
"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",
"headers": {
"Content-Type": "application/json; charset=UTF-8",
"Date": "Wed, 13 Mar 2019 17:50:19 GMT",
"Expires": "Thu, 14 Mar 2019 17:50:19 GMT",
"Date": "Thu, 22 Aug 2019 13:05:39 GMT",
"Expires": "Thu, 22 Aug 2019 13:06:09 GMT",
"Cache-Control": "public, max-age=30",
"Access-Control-Allow-Origin": "*",
"Server": "mafe",
"X-XSS-Protection": "1; mode=block",
"X-XSS-Protection": "0",
"X-Frame-Options": "SAMEORIGIN",
"Server-Timing": "gfet4t7; dur=52",
"Cache-Control": "public, max-age=86400",
"Age": "17",
"Alt-Svc": "quic=\":443\"; ma=2592000; v=\"46,44,43,39\"",
"Server-Timing": "gfet4t7; dur=44",
"Alt-Svc": "quic=\":443\"; ma=2592000; v=\"46,43,39\"",
"Accept-Ranges": "none",
"Vary": "Accept-Encoding",
"Transfer-Encoding": "chunked"
@ -30,5 +29,35 @@
"status_code": 200,
"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"
}
}
]
]

View File

@ -43,7 +43,7 @@ defmodule Mobilizon.Service.Geospatial.GoogleMapsTest do
use_cassette "geospatial/google_maps/search" do
assert %Address{
locality: "Lyon",
description: "10 Rue Jangot, 69007 Lyon, France",
description: "10 Rue Jangot",
region: "Auvergne-Rhône-Alpes",
country: "France",
postal_code: "69007",
@ -52,8 +52,13 @@ defmodule Mobilizon.Service.Geospatial.GoogleMapsTest do
coordinates: {4.8424032, 45.75164940000001},
properties: %{},
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
@ -61,16 +66,17 @@ defmodule Mobilizon.Service.Geospatial.GoogleMapsTest do
use_cassette "geospatial/google_maps/geocode" do
assert %Address{
locality: "Lyon",
description: "10 Rue Jangot, 69007 Lyon, France",
description: "10bis Rue Jangot",
region: "Auvergne-Rhône-Alpes",
country: "France",
postal_code: "69007",
street: "10 Rue Jangot",
street: "10bis Rue Jangot",
geom: %Geo.Point{
coordinates: {4.8424967, 45.751725},
coordinates: {4.8424966, 45.751725},
properties: %{},
srid: 4326
}
},
origin_id: "gm:ChIJrW0QikTq9EcR96jk2OnO75w"
} ==
GoogleMaps.geocode(4.842569, 45.751718, api_key: "toto")
|> hd

View File

@ -39,7 +39,8 @@ defmodule Mobilizon.Service.Geospatial.NominatimTest do
coordinates: {4.8425657, 45.7517141},
properties: %{},
srid: 4326
}
},
origin_id: "osm:3078260611"
} == Nominatim.search("10 rue Jangot") |> hd
end
end
@ -58,7 +59,8 @@ defmodule Mobilizon.Service.Geospatial.NominatimTest do
coordinates: {4.8425657, 45.7517141},
properties: %{},
srid: 4326
}
},
origin_id: "osm:3078260611"
} ==
Nominatim.geocode(4.842569, 45.751718)
|> hd