1
我試圖使用Doctrine ODM存儲在MongoDB中的GeoJSON格式導出的位置: 我要做的就是:
映射:我如何保存以GeoJSON在MongoDB中使用PHP
class Coordinates
{
/** @MongoDB\String */
protected $type;
/** @MongoDB\Hash */
protected $coordinates;
public function __construct($type='Point',$coordinates)
{
$this->setType($type);
$this->setCoordinates($coordinates);
}
當我嘗試存儲一個位置時,我得到如下:
coordinates: { type: "Point", coordinates: { 0: -6.855243444442749, 1: 33.9704221689807 } }
這不是GeoJson格式。 正確的格式應該是
coordinates: { type: "Point", coordinates: [ -6.855243444442749,33.9704221689807 ] }
我該如何做到這一點? 非常感謝!
編輯! 這是我如何將其存儲在PHP:
$coordinates=new Coordinates('Point',[$lng,$lat]);