Phoenix Live View for Real-time Google Maps positions?

I haven’t had time to look into Live View yet, although I’m very excited to do so soon.

One thing I will need in the near future is to add a map that will frequently update object map pointer positions.

Is this a use-case that would be covered by Live View?

1 Like

I don’t see how it wouldn’t possible. Worst case scenario you have to write some JS to push changes to the Map as states change. I’d check out to embed the map in a LiveView and handle an update to change the Place/location attribute. That’d be the quickest solution if it works. If the embed is too static, you may have to roll some JS to interact with the map as the Liveview state change events come in ( I’ll bet you could do live updates with routes, directions, arrival time estimates - the whole enchilada so long as you have that data coming in. Most logistics software nowadays is hitting the Google Maps API under the hood.


Hey! Did you find a solution for this? I have a similar use case.

No, still using Nuxt.js

I haven’t had the time to prototype anything in Live View yet, especially things I’m not sure I’d be able to do (or would be a good fit).

Keep us posted if you end up getting it working :innocent:

I am still learning, but perhaps you could create a Google Maps Web Component.
LiveView also has JS Hooks that could potentially be utilized.
I have an example repo of using Leaflet.js (similar to Google Maps) with LiveView here. It’s pretty basic, but might help.
The web component I use in the repo looks something like this with Phoenix LiveView.

  <leaflet-map lat="51.505" lng="-0.09">
    <%= for marker <- @markers do %>
        lat="<%= %>"
        lng="<%= marker.lng %>"
        selected="<%= marker.selected %>"
        phx-value-id="<%= %>">
          icon-url="<%= get_icon_url(marker.selected) %>"
    <% end %>