半径でジオポイントを見つけようとしましたが、チュートリアルでその方法を説明しました。モンゴース半径でジオポイントを見つける
チュートリアルのスニペット:
まず、スキーマを作成する必要があります。ドキュメントは、地理空間データを格納する方法に関するいくつかの例を示しています。この例では、従来の形式を使用します。経度と緯度を配列に格納することをお勧めします。ドキュメントは値の順序についての使用を警告し、経度が最初に来る。私はdidnの私のプロジェクトにチュートリアルから実装されたソース後 How to use Geospatial Indexing in MongoDB with Express and Mongoose
:
findLocation: function(req, res, next) {
var limit = req.query.limit || 10;
// get the max distance or set it to 8 kilometers
var maxDistance = req.query.distance || 8;
// we need to convert the distance to radians
// the raduis of Earth is approximately 6371 kilometers
maxDistance /= 6371;
// get coordinates [ <longitude> , <latitude> ]
var coords = [];
coords[0] = req.query.longitude;
coords[1] = req.query.latitude;
// find a location
Location.find({
loc: {
$near: coords,
$maxDistance: maxDistance
}
}).limit(limit).exec(function(err, locations) {
if (err) {
return res.json(500, err);
}
res.json(200, locations);
});
}
リファレンスチュートリアルを:
var LocationSchema = new Schema({
name: String,
loc: {
type: [Number], // [<longitude>, <latitude>]
index: '2d' // create the geospatial index
}
});
まず、このような何かを見ることができますあなたのコントローラ内でメソッドを作成することができますデータベースから正しい点を半径で受け取る(点は半径の内側にない)。
私の質問は、半径(キロメートルまたはメートルは関係ありません)でどのように地点を受け取ることができますか?
ありがとう、マイケル。