我有跟随mongoDB文件,它代表当前车辆位置的“GPS”字段 { "_id" : ObjectId("565564e2f3e3f5bd2bdfad18"), "vehicleId" : 6521, "time" : 1448389800, "GPS" : "18.55419790592852,73.80579963326454", "readings" : { "RPM" : { "value"
{ "_id" : ObjectId("565564e2f3e3f5bd2bdfad18"), "vehicleId" : 6521, "time" : 1448389800, "GPS" : "18.55419790592852,73.80579963326454", "readings" : { "RPM" : { "value" : 1000 }, "Speed" : { "value" : 40 } } }
我需要查找此条目是否属于坐标指定的多边形:
{lat: 18.554321, lng: 73.805231}, {lat: 18.553838, lng: 73.804936}, {lat: 18.553584, lng: 73.806524}, {lat: 18.554240, lng: 73.806546}, {lat: 18.554321, lng: 73.805231}
通过参考文件中的GPS字段.
我尝试了以下查询,但我没有得到任何结果:
db.data26.find( { "GPS": { $geoWithin: { $geometry: { type : "Polygon" , coordinates: [ [ [ 73.805231, 18.554321 ], [ 73.804936, 18.553838 ], [ 73.806524, 18.553584 ], [ 73.806546, 18.554240 ], [ 73.805231, 18.554321 ] ] ] } } } } );
任何帮助将不胜感激
您的GPS字段值是字符串“GPS” : “18.55419790592852, 73.80579963326454”
也许为了使用geoWithin你的GPS应该是一个正确顺序的数组,这是[long,lat],如下所示:[73.80579963326454,18.55419790592852]