如何在Php mongodb中使用$ geointersects

时间:2015-02-14 14:08:42

标签: php mongodb mongodb-php

我有像mongodb这样的集合

`{"_id" : ObjectId("54df0a912e2b8df82d15e2dc"),"shopDeliveryArea" : {
            "type" : "Polygon",
            "coordinates" : [
                    [
                            [
                                    12.960308,
                                    77.642759
                            ],
                            [
                                    12.958495,
                                    77.643177
                            ],
                            [
                                    12.957933,
                                    77.644299
                            ],
                            [
                                    12.955367,
                                    77.647154
                            ],
                            [
                                    12.953395,
                                    77.648083
                            ],
                            [
                                    12.952329,
                                    77.649925
                            ],
                            [
                                    12.953475,
                                    77.65048
                            ],
                            [
                                    12.953639,
                                    77.651405
                            ],
                            [
                                    12.954735,
                                    77.651804
                            ],
                            [
                                    12.955287,
                                    77.650502
                            ],
                            [
                                    12.956573,
                                    77.65089
                            ],
                            [
                                    12.956084,
                                    77.653259
                            ],
                            [
                                    12.959188,
                                    77.654081
                            ],
                            [
                                    12.959444,
                                    77.649814
                            ],
                            [
                                    12.960308,
                                    77.642759
                            ]
                    ]
            ]
    }}`

我想检查点是否在此多边形内,并且我使用了以下查询

  `db.collection.find({shopDeliveryArea:{$geoIntersects: {$geometry: {"type": "Point","coordinates": [12.953463, 77.650069]}}}}).pretty()`

返回数据。当我尝试使用php时,它没有返回任何值:(

这是我的代码

      `$condition=array(
            'shopDeliveryArea'=>array(
                '$geoIntersects' =>  array(
                    '$geometry' => array(
                        'type' => 'Point',
                        'coordinates' => array(
                            (double)$currentLatitude, 
                            (double)$currentLongitude   
                        )
                    )
                )
            ),
            'shopCategory' => (int) $orderCategory,
            'isApproved'=>'TRUE'
        );
        $fetch=array(
        );

        $results = $collection->findone($condition,$fetch);`

但是这段代码没有返回任何结果。需要帮助

0 个答案:

没有答案