private void OnLocationChanged( GeoPosition location ) { var evt = LocationChanged; if ( evt != null ) { evt( this, new LocationChangedEventArgs( location ) ); } }
/// <summary> /// Computes the distance to another GeoPosition. /// </summary> public double DistanceTo( GeoPosition other ) { double lat1 = this.Latitude * RadianCoeff, lat2 = other.Latitude * RadianCoeff, lon1 = this.Longitude * RadianCoeff, lon2 = other.Longitude * RadianCoeff; return EarthRadiusInKilometers * 2 * Math.Asin( Math.Min( 1, Math.Sqrt( ( Math.Pow( Math.Sin( ( lat2 - lat1 ) / 2.0 ), 2.0 ) + Math.Cos( lat1 ) * Math.Cos( lat2 ) * Math.Pow( Math.Sin( ( lon2 - lon1 ) / 2.0 ), 2.0 ) ) ) ) ); }
/// <summary> /// Asynchronously gets the user's location. /// </summary> public async Task<Tuple<GeoPosition, GeoLocationStatus>> GetLocationAsync() { try { var geoPosition = await _locator.GetGeopositionAsync(); _lastKnownLocation = PositionFromCoordinate( geoPosition.Coordinate ); return Tuple.Create( _lastKnownLocation, GeoLocationStatus.Success ); } catch { return Tuple.Create( (GeoPosition) null, GeoLocationStatus.Error ); } }
/// <summary> /// Creates a new LocationChangedEventArgs. /// </summary> public LocationChangedEventArgs(GeoPosition location) { Location = location; }
/// <summary> /// Creates a new LocationChangedEventArgs. /// </summary> public LocationChangedEventArgs( GeoPosition location ) { Location = location; }
/// <summary> /// Occurs when the user's position changes. /// </summary> private void Locator_PositionChanged( Geolocator sender, PositionChangedEventArgs args ) { _lastKnownLocation = PositionFromCoordinate( args.Position.Coordinate ); OnLocationChanged( _lastKnownLocation ); }