我希望您能找到附近的位置,因此插入记录如下...
但它返回的是...
这段代码返回一个空列表。我不知道哪里出错了。求帮助!!
db.locationcol.insert({"location":"phase 8,mohali ,punjab ,india","service":"psychologist","loc":{"lon":76.703347,"lat":30.710459}})
然后在终端上执行查询。
db.runCommand(
{
geoNear: "locationcol",
near: { type: "Point", coordinates: [ 76.720845, 30.712097 ] },
spherical: true,
query: { category: "public" }
})
但它返回的是...
{ "ok" : 0, "errmsg" : "no geo indices for geoNear" }
我也在尝试使用Spring ...
public GeoResults getnearby(double longitude,double latitude, String service) {
Point point = new Point(longitude,latitude);
Query query = new Query(Criteria.where("service").is(service));
query.fields().include("service").include("location").include("loc");
NearQuery nearQuery = NearQuery.near(point).maxDistance(new Distance(50, Metrics.KILOMETERS));
nearQuery.query(query);
nearQuery.num(20);
GeoResults<locationcol> data = operations.geoNear(nearQuery, locationcol.class,"locationcol");
return data;
}
这段代码返回一个空列表。我不知道哪里出错了。求帮助!!