Skip to content
Advertisement

Laravel livewire – how to pass geo coordinates of user to livewire component

I am trying to send geo coordinates (latitude and longitude) of user to a livewire component to load nearby places. However I am unable to send it because they are javascript variables. Question is how do I send a javascript variable to a livewire component?

Here is what I have done so far.

JavaScript
JavaScript
JavaScript

Advertisement

Answer

You’ll need to emit an event globally from you script. like this:

JavaScript

After that you can listen to this event from your livewire component class like this:

JavaScript

Then set your passed lat long using setLatitudeLongitude function inside your livewire component class.

JavaScript

Let me know if you need further explanation 🙂

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement