I'm trying to use Geo library to store Geo.Point via Phoenix model changeset. My params are: {coordinates: [49.44, 17.87]}
or more prefer would be {coordinates: {latitude: 49.44, longitude: 17.87}}
In iex console I tried:
iex(5)> changeset = Place.changeset(%Place{}, %{coordinates: [49.44, 17.87]})
%Ecto.Changeset{action: nil, changes: %{}, constraints: [],
errors: [coordinates: "is invalid"], filters: %{}
model: %Myapp.Place{__meta__: #Ecto.Schema.Metadata<:built>,
coordinates: nil, id: nil, inserted_at: nil, updated_at: nil}, optional: [],
opts: [], params: %{"coordinates" => [49.445614899999995, 17.875574099999998]},
repo: nil, required: [:coordinates],
All other attempts ended by Poison.Parser errors.
How should looks params from client side to create valid changeset?
Model:
defmodule MyApp.Place do
use MyApp.Web, :model
schema "place" do
field :coordinates, Geo.Point
timestamps
end
@required_fields ~w(coordinates)
@optional_fields ~w()
def changeset(model, params \\ :empty) do
model
|> cast(params, @required_fields, @optional_fields)
end
end
{coordinates: {latitude: 49.44, longitude: 17.87}}
to extractlatitude
&longitude
into%Geo.Point{}
in right format? – Salesroom