ユーザー間の距離を計算する必要がある状況があります。この特定のシナリオで私は持っています:ユーザ間の距離を計算するメテオ。サーバー側とクライアント側
雇用者の地位 - 1つのユーザーの1つの場所。 候補ジオロケーション - ユーザーごとに1つの場所がありますが、雇用主が候補リストを生成するときに複数の候補があります。
私は現在、ジオロケーションをワイヤー上に押し込んでクライアント側で基本距離公式を実行しているので、雇用者と各候補者の間の距離を把握し、要求に応じて候補者を表示/非表示にしています。
私は、サーバー側で計算を実行して、ただ1つの数値、すなわち、各候補につき10kmを表す10。その後、その番号でフィルタを実行します。
これまでのところ、私はコレクションとフィールドだけをワイヤーにプッシュしました。下の数式をサーバー側で実行し、1つの数値を渡してユーザーに「添付」することは可能ですか?
第2の質問は、メテオのベストプラクティスは何ですか?
私はまだコードを学習しているので、これが本当に明白な質問であれば謝ります。
クライアント側
パス:List.js
specialisations = specialisations.filter(function(element){
let distance = Template.instance().distanceFromEmployerFilter.get();
let user = Meteor.users.findOne({_id: element.candidateUserId});
let candidateLat = user && user.profile && user.profile.address && user.profile.address.latitude;
let candidateLong = user && user.profile && user.profile.address && user.profile.address.longitude;
let company = CompanyDetails.findOne({employerUserId: Meteor.userId()});
let companyLat = company && company.latitude;
let companyLong = company && company.longitude;
var R = 6371; // Radius of the earth in km
var dLat = (companyLat-candidateLat) * (Math.PI/180);
var dLon = (companyLong-candidateLong) * (Math.PI/180);
var a =
Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.cos((candidateLat) * (Math.PI/180)) * Math.cos((companyLat) * (Math.PI/180)) *
Math.sin(dLon/2) * Math.sin(dLon/2)
;
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
var distanceInKM = R * c; // Distance in km
if (distanceInKM <= distance) {
return true;
} else {
return false;
}
});
オプションである[$近く](HTTPS:/ /docs.mongodb.com/v3.2/reference/operator/query/near/#op._S_near)*サーバー上で* –