我正在尝试使用 Doctrine ODM 在 MongoDb 中以 GeoJson 格式存储位置:我所做的是:
映射:
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]);