我有一些代码及其工作。但谁能知道更多的解决方案?由于我还没有弄清楚如何将多边形转换为圆形,以及如何将多边形的中心作为圆形在地图上显示。 :
exports.getRoomsNears = function (req, res) {
log.info('get all rooms');
var limit = req.params.limit || 10
var coords = [];
coords[0] = req.params.latitude;
coords[1] = req.params.longitude;
Room.find({
location: {
$geoIntersects: {
$geometry: {
type: "Point",
coordinates: coords
}
}
}}).limit(limit).exec(function (err, locations) {
if (err) {
return res.json(500, err);
}
log.info(locations);
res.json(200, locations);
});};
我的圈子有架构
var schema = new Schema ({
name: {
type: String,
required: true
},
inPrivate: {
type: Boolean,
required: false
},
location: {
type: { type: String, "enum": [
"Point",
"MultiPoint",
"LineString",
"MultiLineString",
"Polygon",
"MultiPolygon"
] },
coordinates: { type: Array }
},
radius : Number,
created: {
type: Date,
default: Date.now
}});
还有另一个想法是正确的,在一定范围内发出一个圆圈,然后在客户端检查该点是否与圆相交?