使用mongo,我想将用户的地理坐标与每个代表定义的地理边界的文档集合进行比较。这是我想要做的,但不能工作。其他建议也可以获得相同的结果。 集合中的文档看起来像这样(那些是曼哈顿坐标,如果你从一个坐标到下一个坐标顺序绘制一条线,它包裹曼哈顿)
{
"__v" : 1,
"_id" : ObjectId("53220803a74a16da9c729202"),
"name" : "Manhattan",
"boundary" : {
"type" : "Polygon",
"coordinates" : [
[
[
-74.01237999999999,
40.69967
],
[
-73.97895,
40.71076
],
[
-73.97169,
40.73049
],
[
-73.92828,
40.79605
],
[
-73.95547999999999,
40.82635
],
[
-74.00901,
40.75431
],
[
-74.01961,
40.7059
]
]
]
}
}
然后我使用以下查询进行检查
db.collection.find( { boundary :
{ $geoIntersects :
{ $geometry :
{ type : "Point" ,
coordinates : [ [user_long, user_lat] ]
} } } } ).exec(function(err, city){
console.log(err, "error");
res.send({agent_count : city});
});