Closed matb987 closed 6 months ago
<x-maps-leaflet :zoomLevel="6"
:centerPoint="['lat' => 52.16444513293423, 'long' => 5.985622388024091]"
:markers="[['lat' => 52.16444513293423, 'long' => 5.985622388024091, 'icon' => 'https://cdn0.iconfinder.com/data/icons/small-n-flat/24/678111-map-marker-512.png', 'iconSizeX' => 32, 'iconSizeY' => 32]]"
></x-maps-leaflet>
Can you try this?
how can i make it so it can get the infomation from the database ? eg using a variable
here is my current code if it helps
$drivers = DB::table('users')->where('status', 'active')->get();
//list for drivers location without key
//set array values
$markers = [];
foreach ($drivers as $driver) {
$markers[] = [
'lat' => $driver->latitude,
'long' => $driver->longitude,
'infoWindow' => [
'content' => $driver->name,
],
];
}
return view('livewire.driver-map', compact('drivers', 'markers'));
it works with the code
for ($i = 0; $i < 3; $i++) {
$markers[] = [
'lat' => 51 + $i,
'long' => -3 + $i
];
}
but not with a foreach loop like this
foreach ($drivers as $driver) {
$markers[] = [
'lat' => $driver->lat,
'long' => $driver->long,
];
}
I got it working with the following code. not sure if it is the best way but it works
$drivers = DB::table('users')->where('status', 'active')->get();
//create array
$markers = [];
foreach ($drivers as $driver) {
//if the driver has a location
if ($driver->latitude != null && $driver->longitude != null) {
//get the latitude and longitude
$lat = $driver->latitude;
//convert to float
$lat = (float)$lat;
$long = $driver->longitude;
//convert to float
$long = (float)$long;
//append to push array
array_push($markers, ['lat' => $lat, 'long' => $long]);
}
}
Happy it works now :)
an you give me an example of how you would make this loop as i keep getting the error: Undefined array key 0 controller code:
View Code