我正在尝试使用geojson在Google地图上绘制多边形。这是PHP代码,我试图使用从查询结果数组返回的四个边界值来构建多边形:
$arr3_poly = Array(
"type" => "Polygon",
"coordinates" => Array()
);
foreach ($q->result_array() as $row) {
$arr3_poly["coordinates"][] = Array(
floatval($row['v3_bounds_sw_lat']),
floatval($row['v3_bounds_sw_lng']),
floatval($row['v3_bounds_ne_lat']),
floatval($row['v3_bounds_ne_lng']),
);
}
当我执行json_encode($arr3_poly, JSON_PRETTY_PRINT);
时,这是结果输出:
{
"type": "Polygon",
"coordinates": [
[
43.8526377,
-79.0499898,
43.8526509,
-79.0499877
],
[
43.8526546,
-79.0501977,
43.8526678,
-79.0501957
],
[
43.8526716,
-79.0504057,
43.8526848,
-79.0504037
]
]
}
此geojson一定有问题,因为当我尝试在geojsonlint.com验证时,它会返回错误Failed to validate field 'coordinates' list schema.
:
任何想法我做错了什么?感谢。
答案 0 :(得分:1)
这适用于我geojsonlint.com(略微改变你的点,使它看起来不像一条直线):
{
"type": "Polygon",
"coordinates": [
[
[43.8526377,-79.0499898],
[43.854,-79.051],
[43.8526716,-79.0504057],
[43.8526377,-79.0499898]
]
]
}
然而,仔细看看那张地图,他们在南极洲,你可能想要这个,这是在加拿大,多伦多附近:
{
"type": "Polygon",
"coordinates": [
[
[-79.0499898,43.8526377],
[-79.051,43.854],
[-79.0504057,43.8526716],
[-79.0499898,43.8526377]
]
]
}
元素的顺序必须遵循x,y,z顺序(经度,纬度,高度) 地理坐标参考系中的坐标。)
与google.maps.LatLng对象(即纬度,经度)的顺序相反。