Doug Black
Posts: 0
Joined: Wed Aug 14, 2013 11:36 am

Compare Two Geopoints

I'm trying to figure out how to compare two Geopoints to see if the person using the app is in the vicinity of the location.

I pre-programmed the Geopoint of the business. I also use location services to find the location of the person using the app. I have the two points; how do I compare them? I was trying to use $nearsphere, but I'm not sure how to go about it.

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Compare Two Geopoints

Can you show us how exactly you tries to compare the two points?

Doug Black
Posts: 0
Joined: Wed Aug 14, 2013 11:36 am

Compare Two Geopoints

Actually, I found a way around it. I think $nearsphere is only for queries, which I was past that point. I used this function:
precode
function distance(lat1, lon1, lat2, lon2, unit) {
var radlat1 = Math.PI * lat1/180
var radlat2 = Math.PI * lat2/180
var radlon1 = Math.PI * lon1/180
var radlon2 = Math.PI * lon2/180
var theta = lon1-lon2
var radtheta = Math.PI * theta/180
var dist = Math.sin(radlat1) * Math.sin(radlat2) + Math.cos(radlat1) * Math.cos(radlat2) * Math.cos(radtheta);
dist = Math.acos(dist)
dist = dist * 180/Math.PI
dist = dist * 60 * 1.1515
if (unit=="K") { dist = dist * 1.609344 }
if (unit=="N") { dist = dist * 0.8684 }
return dist
}
/code/pre

Oleg Danchenkov
Posts: 0
Joined: Tue Apr 30, 2013 5:51 pm

Compare Two Geopoints

Hi Doug. Thanks for sharing.

Return to “Issues”