BikeInCity.Utils.GeoMath.ComputeDistance C# (CSharp) Метод

ComputeDistance() публичный статический Метод

Returns distsance in meters between two points of earth using the Spherical Law of Cosines
public static ComputeDistance ( double startLat, double startLng, double endLat, double endLng ) : int
startLat double
startLng double
endLat double
endLng double
Результат int
        public static int ComputeDistance(double startLat, double startLng, double endLat, double endLng)
        {
            var lat1 = ToRad(startLat);
              var lng1 = ToRad(startLng);
              var lat2 = ToRad(endLat);
              var lng2 = ToRad(endLng);

              return SphericalEarthProjectedToAPlane(lat1, lng1, lat2, lng2);
        }

Usage Example

Пример #1
0
        public static ObservableCollection <BikeStationViewModel> GetNearStations(Location coordinate, IEnumerable <BikeStationViewModel> allStations, bool from)
        {
            //return collection
            ObservableCollection <BikeStationViewModel> collection = new ObservableCollection <BikeStationViewModel>();

            if (allStations != null)
            {
                List <BikeStationViewModel> stations = null;
                foreach (BikeStationViewModel station in allStations)
                {
                    if (from)
                    {
                        station.WalkDistanceTo = GeoMath.ComputeDistance(station.Location.Latitude, station.Location.Longitude, coordinate.Latitude, coordinate.Longitude);
                    }
                    else
                    {
                        station.WalkDistanceFrom = GeoMath.ComputeDistance(station.Location.Latitude, station.Location.Longitude, coordinate.Latitude, coordinate.Longitude);
                    }
                }

                if (from)
                {
                    stations = allStations.OrderBy(x => x.WalkDistanceTo).Take(5).ToList();
                }
                else
                {
                    stations = allStations.OrderBy(x => x.WalkDistanceFrom).Take(5).ToList();
                }

                foreach (BikeStationViewModel station in stations)
                {
                    collection.Add(station);
                }
            }
            else
            {
                throw new Exception(AppResources.Message_StationsNotLoaded);
            }
            return(collection);
        }