LarsWiegers / laravel-maps

Your laravel maps libary.
https://github.com/LarsWiegers/laravel-maps
MIT License
254 stars 35 forks source link

Multiple markers dynamically #32

Closed rjcalifornia closed 2 years ago

rjcalifornia commented 2 years ago

I know blade tags dont have to use the {{ and }} to pass data

https://github.com/LarsWiegers/laravel-maps/issues/6

Currently, there's no way to add markers dynamically. For instance, I query the DB and get an array of coordinates. Currently you cannot loop through each location to place a marker on a single map (not multiple maps).

May be there's a way but I can't find it.

LarsWiegers commented 2 years ago

can you give some example code of what you are trying to do?

rjcalifornia commented 2 years ago

Sorry for the late reply. If I wanted to make place multiple markes on the SAME map, it won't work:


<x-maps-leaflet :markers="[
@foreach ($locations as $location)
['lat' => $location->latitude, 'long' => $location->longitude',
@endforeach
]"></x-maps-leaflet>
LarsWiegers commented 2 years ago

So it is probably a good idea to do this loop in your controller that way you can pass a single array to the component.

rjcalifornia commented 2 years ago

So it is probably a good idea to do this loop in your controller that way you can pass a single array to the component.

Well, yeah. I actually did that after the first code I posted didn't work. I didn't work, the map was blank for some reason.

LarsWiegers commented 2 years ago

Without more code / errors in the console you are getting its going to be hard for me to diagnose the problem

rjcalifornia commented 2 years ago

Alright...