使用 Doctrine MongoDB ODM 的 geonear 方法中的错误距离 [英] Wrong distance in geonear method with Doctrine MongoDB ODM

查看:92
本文介绍了使用 Doctrine MongoDB ODM 的 geonear 方法中的错误距离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将 DoctrineMongoDBBundle 与 Symfony2 一起使用,但我遇到了地理坐标问题.这工作正常,但当经度是这样的: 0.635467 代码不起作用.我有更多的地理坐标,只有当它以 0 开头时才会失败.距离字段为 NULL.

I'm using DoctrineMongoDBBundle with Symfony2 and I've a problem with geocoordinates. This works fine but when the longitude is for example like that: 0.635467 the code doesn't work. I have more geocoordinates and only fails when it begins with 0. and the distance field is NULL.

这是我的代码:

$locations = $dm->createQueryBuilder('MyBundle:Location')
                    ->field('id')->in($arrayIds)
                    ->field('geocoordinates')
                    ->geoNear($geocodes['lat'],$geocodes['lon'])
                    ->getQuery()->execute()->toArray();

我正在关注此链接:http://docs.doctrine-project.org/projects/doctrine-mongodb-odm/en/latest/reference/geospatial-queries.html 但使用 geonear 方法.

I'm following this link: http://docs.doctrine-project.org/projects/doctrine-mongodb-odm/en/latest/reference/geospatial-queries.html but with the geonear method.

推荐答案

geoNear() 查询构建器方法不适用于字段.near() 是跟随 field() 焦点的构建器方法.您可以在 中查看这两种构建器方法的作用Builder.php 在doctrine/mongodb 项目中.请注意,geoNear() 更改了查询类型(类似于 update() 所做的).然后在 Query.php<中检查查询类型/a>(遵循 switch 语句)并确定我们如何对集合发出查询.有些是实际的查询操作,但诸如 map/reduce 和 geoNear 之类的都是命令.

The geoNear() query builder method is not intended to be used on a field. near() is the builder method that would follow a field() focus. You can see what both of these builder methods do in Builder.php within the doctrine/mongodb project. Note that geoNear() changes the query type (similar to what update() does). The query type is then checked in Query.php (follow the switch statement) and determines how we issue the query on the collection. Some are actual query operations, but things like map/reduce and geoNear are commands.

看看下面的代码是否有效:

See if the following code works:

$dm->createQueryBuilder('MyBundle:Location')
    ->geoNear($geocodes['lat'],$geocodes['lon'])
    ->field('id')->in($arrayIds)
    ->getQuery()->execute()->toArray();

如果没有,请调试 Query.php 传递给 Collection::near() 方法的值.或者,您可以使用 Query::getQuery() 方法调试构建器生成的整个查询数组.

If not, please debug the values that Query.php passes to the Collection::near() method. Alternatively, you can debug the entire query array generated by the builder by using the Query::getQuery() method.

这篇关于使用 Doctrine MongoDB ODM 的 geonear 方法中的错误距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆