嗨,我在PHP中使用FeatureCollection输出遇到麻烦。
背景:
我有一个MySQL服务器,该服务器包含一个地理位置表,该表具有用户名,用户经度和纬度。目前,有3条记录具有唯一的用户名,我打算将其用作MapID。所以我的桌子看起来像这样
用户名|经度|纬度
sy456 | 45.78888 | 5822.35
s744 | 85.6632 | 47.52366
S69995 | 456789.23 | 4572.332
以下是我的代码
<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE, OPTIONS');
header('Access-Control-Allow-Headers: Origin, Content-Type, X-Auth-Token');
header("Content-Type: application/json; charset=UTF-8");
error_reporting(E_ALL);
include('global.php');
$connection = new mysqli(dbhost, dbuser, dbpassword, dbname);
$query = "SELECT longitude, latitude from geolocation";
$result = $connection -> query($query);
while($rs1 = $result->fetch_array(MYSQLI_ASSOC)) {
$long = $rs1['longitude'];
$latitude = $rs1['latitude'];
$geometry_array = array(
"type" => "Point",
"coordinates" => array ($long,$latitude)
);
$data = (array(
'geometry'=>$geometry_array,
'type' =>"Feature",
"properties" =>"{}"
));
$output = (array(
'type' => "FeatureCollection",
'features' => array($data)));
}
echo json_encode($output);
$connection->close(); //Closing SQL connection
?>