【问题标题】:How do I store GeoJson in MongoDB with PHP如何使用 PHP 在 MongoDB 中存储 GeoJson
【发布时间】:2014-12-26 13:41:52
【问题描述】:


我正在尝试使用 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]);

【问题讨论】:

    标签: php mongodb odm


    【解决方案1】:

    是的! 我在推特上得到了答案:P 我应该将整个坐标字段映射为哈希

    【讨论】:

      猜你喜欢
      • 2015-11-24
      • 2012-06-23
      • 2018-10-23
      • 2016-08-22
      • 2017-04-17
      • 1970-01-01
      • 2016-06-03
      • 1970-01-01
      • 2015-08-22
      相关资源
      最近更新 更多