<?php 
require 'vendor/autoload.php';
use Grimzy\LaravelMysqlSpatial\Types\Point;
use Grimzy\LaravelMysqlSpatial\Types\Polygon;
use Grimzy\LaravelMysqlSpatial\Types\LineString;
require 'inc/Config.php';
header('Content-Type: application/json');
error_reporting(E_ALL);
$id = $_GET['id'];
$coordinates = $lundry->query("SELECT ST_AsGeoJSON(`coordinates`),ST_AsText(ST_Centroid(`coordinates`)) as center  FROM `zones` WHERE id=".$id."")->fetch_array();
$data = json_decode($coordinates[0]);
$rows = $data->coordinates[0];
$data = array();
$js = array();
foreach ($rows as $row) {
	$data['lat'] = $row[1];
$data['lng'] = $row[0];
$js[] = $data;
}
$center = $coordinates[1];
$str = ['POINT','(',')'];
$rplc =['','',''];
$center = explode(' ',str_replace($str,$rplc,$center));
$jp = array('lat'=>(float)$center[1],'lng'=>(float)$center[0]);
echo json_encode(array('coordinates'=>$js,'center'=>$jp));


?>


