Search code examples
databaselaravelleafletcoordinatesopenstreetmap

How to display coordinates from db in OSM


In DB i have 5 tables, and in one of them i have devices with coordinates. I want to show that devices on Open Street Map, but don't know how to show it from DB to map. I even have that table in same blade with map.

Has anyone done this before?


Solution

  • Remove: var koordinate = [{{$dev -> x}}, {{$dev -> y }}];

    Change $dev to $device var koordinate = {!! json_encode($device->toArray()) !!};

    And use this Code to add the Markers:

    for (var i=0; i < koordinate.length; i++) {
       if(koordinate[i].x && koordinate[i].y){
         var marker = L.marker([koordinate[i].x, koordinate[i].y])
         .bindPopup(""+koordinate[i].device_type)
         .addTo(map);
       }
    }