how to check radius of 10 meter from x,y position

2019-07-23 21:27发布

问题:

i have this position from GPS:

40.715192,-74.005795

how to check if i in the range of 10 meter radius ?

thank's in advance

回答1:

Use Haversine formula http://en.wikipedia.org/wiki/Haversine_formula

Pseudocode:

R = 6371; // corrected earth radius, km
dLat = degToRad(lat2-lat1);
dLon = degToRad(lon2-lon1); 
a = sin(dLat/2) * sin(dLat/2) +
        cos(degToRad(lat1)) * cos(degToRad(lat2)) * 
        sin(dLon/2) * sin(dLon/2); 
c = 2 * atan2(sqrt(a), sqrt(1-a)); 
distance = R * c;

degToRad converts degress to radians, see e.g. here



回答2:

I was looking for something similar and found this: http://megocode3.wordpress.com/2008/02/05/haversine-formula-in-c/



标签: c# gps