Exemple #1
0
 // Calculate distance from each station to user.
 private void calDists(GpsPos userPos, List <FreeStation2> fFullList)
 {
     foreach (var fcr in fFullList)
     {
         fcr.Dist = posDist(fcr, userPos);
     }
 }
Exemple #2
0
        // Distance using Pythagoras’ theorem.
        public int posDist(GpsPos p1, GpsPos p2)
        {
            var lat1 = p1.Lat / 360;
            var lat2 = p2.Lat / 360;
            var lon1 = p1.Lon / 360;
            var lon2 = p2.Lon / 360;

            var y = lat2 - lat1;
            var x = (lon2 - lon1) * Math.Cos((lat2 + lat1) / 2);

            return((int)(earthRadius * Math.Sqrt(Math.Pow(x, 2) + Math.Pow(y, 2))));
        }