Storing geolocation with phoenix live view?

Phoenix live view have great features, like form validation, and using changesets on errors so the data are preserved after a bad form submission.

so how do you store geolocation and also display it on a map (like OSM, or Google Maps)

is this something you looking for


I am looking for storing the geolocation with liveview (with a form), this page does not explain how to use location in a form and a changeset, etc.

I haven’t done any work in this area myself (yet), but if you are using PostGIS, there is a library that provides the data type support for Ecto - GitHub - bryanjos/geo_postgis: Postrex Extension for PostGIS. Some more explanation around using it in changesets (including project setup / requirements) is here: Playing with GPX tracks in Elixir and PostGIS · Kacper Golinski (not LiveView, but hopefully gives you some pointers). The author, @caspg, is on the forums, but the best approach would be to try and combine what’s in there with general LiveView / changeset validation approaches and come back with specific questions.

1 Like

geo_postgis is definitely the way to go for data validation and storage of locations, here’s our implementation (notice field(:geom, Geo.PostGIS.Geometry) in the schema and validate_coordinates/1): bonfire_geolocate/geolocation.ex at main · bonfire-networks/bonfire_geolocate · GitHub

for detecting the user’s location I use Leaflet in a hook and pass it to LiveView in an event: bonfire_geolocate/extension.js at main · bonfire-networks/bonfire_geolocate · GitHub