I am using MapboxGLJS. I retrieve the coordinates from my database and I put it in GeoJSON format on PHP which look like this:
<?php
$sql = "SELECT * FROM waypoint";
$server = "localhost";
$username = "root";
$password = "";
$db = "scandrone";
$conn = mysqli_connect($server, $username, $password, $db);
$result = mysqli_query($conn, $sql);
$geojson = array('type' => 'FeatureCollection', 'features' => array());
while($row = mysqli_fetch_assoc($result)){
$marker = array(
'type' => 'Feature',
'features' => array(
'type' => 'Feature',
"geometry" => array(
'type' => 'Polygon',
'coordinates' => array(
$row['longitude'],
$row['latitude']
)
)
)
);
}
echo json_encode($marker);
?>
And when i did an "echo json_encode($marker);" i got this
[{"type":"geojson","data":{"type":"Feature","geometry":{"type":"Polygon","coordinates":{"longitude":"2.0556640625005","latitude":"45.641158147526"}}}},{"type":"geojson","data":{"type":"Feature","geometry":{"type":"Polygon","coordinates":{"longitude":"3.3959960937499","latitude":"44.852208244354"}}}},{"type":"geojson","data":{"type":"Feature","geometry":{"type":"Polygon","coordinates":{"longitude":"1.4404296875004","latitude":"44.508493826826"}}}}]
Now I need to display this on my map. How can I do this?