예제 #1
0
 public double DistanceTo(GeoPosition pos, Unit unit = Unit.Km)
 {
     var rlat1 = Math.PI * this.Latitude / 180;
     var rlat2 = Math.PI * pos.Latitude / 180;
     var rlon1 = Math.PI * this.Longitude / 180;
     var rlon2 = Math.PI * pos.Longitude / 180;
     var theta = this.Longitude - pos.Longitude;
     var rtheta = Math.PI * theta / 180;
     var dist = Math.Sin(rlat1) * Math.Sin(rlat2) + Math.Cos(rlat1) * Math.Cos(rlat2) * Math.Cos(rtheta);
     dist = Math.Acos(dist);
     dist = dist * 180 / Math.PI;
     dist = dist * 60 * 1.1515;
     if (unit == Unit.Km) { dist = dist * 1.609344; }
     if (unit == Unit.Miles) { dist = dist * 0.8684; }
     return dist;
 }
예제 #2
0
        public async Task<GeoPosition> GetLocationAsync()
        {
            Geolocator geolocator = new Geolocator();
            geolocator.DesiredAccuracyInMeters = 50;

            Geoposition geoposition = await geolocator.GetGeopositionAsync(
             maximumAge: TimeSpan.FromMinutes(5),
             timeout: TimeSpan.FromSeconds(10)
             );

            if (geoposition == null)
                return null;

            this.LastKnowPosition = new GeoPosition(geoposition.Coordinate.Latitude, geoposition.Coordinate.Longitude);

            return this.LastKnowPosition;
        }
예제 #3
0
        public double DistanceTo(GeoPosition pos, Unit unit = Unit.Km)
        {
            var rlat1  = Math.PI * this.Latitude / 180;
            var rlat2  = Math.PI * pos.Latitude / 180;
            var rlon1  = Math.PI * this.Longitude / 180;
            var rlon2  = Math.PI * pos.Longitude / 180;
            var theta  = this.Longitude - pos.Longitude;
            var rtheta = Math.PI * theta / 180;
            var dist   = Math.Sin(rlat1) * Math.Sin(rlat2) + Math.Cos(rlat1) * Math.Cos(rlat2) * Math.Cos(rtheta);

            dist = Math.Acos(dist);
            dist = dist * 180 / Math.PI;
            dist = dist * 60 * 1.1515;
            if (unit == Unit.Km)
            {
                dist = dist * 1.609344;
            }
            if (unit == Unit.Miles)
            {
                dist = dist * 0.8684;
            }
            return(dist);
        }