简体   繁体   中英

How to generate the form for a Geo custom type in Phoenix

On my Elixir / Phoenix app I have an Address model that has a location field on it.

The field is a Geo.Geometry custom type from the Geo library, with the following structure:

%Geo.Point{coordinates: {30, -90}, srid: 4326}

I am looking for a way to generate a form for my Address model that includes this location , but I'm not sure what's the proper way to do this.

I was thinking about adding virtual fields to my Address model, like lat and lng , use them in the form and then "translate" those fields into a %Geo.Point in the Address.changeset function.

Is that the right way to go, or is there a more straightforward solution? And if so, how to do this in the changeset?

Many thanks.

我建议的方法终于奏效了:将latlng虚拟字段添加到Address模型,然后使用put_changesAddress changeset中设置my location字段的值。

Should avoid polluting schema with UI requirements. I strongly recommend reading José Valim post explaining the schemaless queries.

http://blog.plataformatec.com.br/2016/05/ectos-insert_all-and-schemaless-queries/

Hope it helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM