public void StartLocationUpdates() { _timer = new Timer(_timeupdates); _timer.Elapsed += OnTimerElapsed; _timer.Start(); IsGPSStarted = false; if (CLLocationManager.LocationServicesEnabled) { IsGPSStarted = true; LocMgr.DesiredAccuracy = 1; LocMgr.LocationsUpdated += (object sender, CLLocationsUpdatedEventArgs e) => { if (_timesuccess) { if (LocationUpdated != null) { LocationUpdated.Invoke(this, new LocationUpdatedEventArgs(e.Locations[e.Locations.Length - 1])); } _timesuccess = false; _timer.Enabled = true; } }; LocMgr.StartUpdatingLocation(); } }
/* * Redirect location updates to the event */ public void OnLocationUpdate(LocationResult result) { if (result == null) { LocationUpdated?.Invoke(this, null); return; } LocationUpdated?.Invoke(this, new LocationEventArgs(result.LastLocation.Longitude, result.LastLocation.Latitude)); }
private void _geoLocator_PositionChanged(Geolocator sender, PositionChangedEventArgs args) { CurrentLocation = new GeoLocation() { Altitude = args.Position.Coordinate.Point.Position.Altitude, Latitude = args.Position.Coordinate.Point.Position.Latitude, Longitude = args.Position.Coordinate.Point.Position.Longitude, LastUpdated = DateTime.Now.ToJSONString() }; RaisePropertyChanged(nameof(CurrentLocation)); LocationUpdated?.Invoke(this, CurrentLocation); }
void LogLocation(Location location) { if (location != null) { Log.Info(CLIENT_LOG_NAME, $"Latitude: {location.Latitude}"); Log.Info(CLIENT_LOG_NAME, $"Longitude: {location.Longitude}"); Log.Info(CLIENT_LOG_NAME, $"Provider: {location.Provider}"); Latitude = location.Latitude; Longitude = location.Longitude; LocationUpdated?.Invoke(this, null); } }
public void TriggerLocationUpdate(CLLocation[] coreLocations) { foreach (var coreLocation in coreLocations) { var args = new LocationManagerUpdate { NewLocation = coreLocation.ToLocation(), OldLocation = LastLocation }; LocationUpdated?.Invoke(this, args); App.LocationUpdated(this, args); LastLocation = coreLocation.ToLocation(); } }
public void Start() { _locator = CrossGeolocator.Current; _cancelationTokenSource = new CancellationTokenSource(); RecurrentCancellableTask.StartNew(async() => { var location = await _locator.GetPositionAsync(TimeSpan.FromSeconds(10), _cancelationTokenSource.Token).ConfigureAwait(false); LocationUpdated?.Invoke(this, new LocationUpdatedEventArgs(new Location { Longitude = location.Longitude, Altitude = location.Altitude, Latitude = location.Latitude })); }, TimeSpan.FromSeconds(10), _cancelationTokenSource.Token, TaskCreationOptions.LongRunning); }
public void StartUpdatingLocation() { _locationManager.StartUpdatingLocation(); Device.StartTimer(new TimeSpan(0, 0, 1), () => { if (_locationManager.Location != null) { LastLocation = _locationManager.Location.ToLocation(); LocationUpdated?.Invoke(this, new LocationManagerUpdate { NewLocation = LastLocation }); _hasInitialLocation = true; } return(!_hasInitialLocation); }); }
public override void DidUpdateBMKUserLocation(BMKUserLocation userLocation) { mapView.UpdateLocationData(userLocation); if (userLocation.Location == null) { return; } LocationUpdated?.Invoke(this, new LocationUpdatedEventArgs { Coordinate = userLocation.Location.Coordinate.ToUnity(), Direction = userLocation.Heading?.TrueHeading ?? double.NaN, Altitude = userLocation.Location.Altitude, Accuracy = Math.Max(userLocation.Location.HorizontalAccuracy, userLocation.Location.VerticalAccuracy), Satellites = -1 }); }
public TestBkgdLocationUpdates() { _locationManager = new CLLocationManager(); _locationManager.PausesLocationUpdatesAutomatically = false; _locationManager.RequestAlwaysAuthorization(); _locationManager.AllowsBackgroundLocationUpdates = true; _locationManager.LocationsUpdated += (object sender, CLLocationsUpdatedEventArgs e) => { var locationsArray = e.Locations; if ((locationsArray != null) && (locationsArray.Length > 0)) { var lastLocation = locationsArray[locationsArray.Length - 1]; LocationUpdated.Invoke(sender, new LocationUpdatedEventArgs(lastLocation)); } }; }
public void OnReceiveLocation(BDLocation location) { if (stopped) { return; } //Debug.WriteLine("LocType: " + location.LocType); switch (location.LocType) { default: break; case BDLocation.TypeServerError: case BDLocation.TypeNetWorkException: case BDLocation.TypeCriteriaException: break; case BDLocation.TypeGpsLocation: case BDLocation.TypeNetWorkLocation: case BDLocation.TypeOffLineLocation: BMap.MyLocationData loc = new BMap.MyLocationData.Builder() .Accuracy(location.Radius) .Direction(location.Direction) .Latitude(location.Latitude) .Longitude(location.Longitude) .Build(); mapView.Map.SetMyLocationData(loc); LocationUpdated?.Invoke(this, new LocationUpdatedEventArgs { //Coordinate = new Coordinate(loc.Latitude, loc.Longitude), Direction = location.Direction, Accuracy = location.HasRadius ? location.Radius : double.NaN, Altitude = location.HasAltitude ? location.Altitude : double.NaN, Satellites = location.SatelliteNumber, Type = location.LocTypeDescription }); return; } Failed?.Invoke(this, new LocationFailedEventArgs(location.LocType.ToString())); }
private async Task ReadAsync() { await Task.Run(() => { using (var fileStream = new FileStream(_currentJournalFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) using (StreamReader file = new StreamReader(fileStream)) using (JsonTextReader reader = new JsonTextReader(file)) { reader.SupportMultipleContent = true; var jsonSerializer = new JsonSerializer(); DateTime newestEventTime = _latestEventTime; dynamic logEvent = null; while (reader.Read()) { logEvent = jsonSerializer.Deserialize(reader); if (logEvent != null && (_latestEventTime == null || logEvent.timestamp > _latestEventTime)) { HandleLogEvent(logEvent); } } if (logEvent != null) { _latestEventTime = logEvent.timestamp; } } // Fire events for new information if (_isPlayerInfoChanged) { PlayerInfoUpdated?.Invoke(this, Log); _isPlayerInfoChanged = false; } if (_isLocationChanged) { LocationUpdated?.Invoke(this, Log); _isLocationChanged = false; } }); }
public void ForceLocationUpdate() { LocationUpdated?.Invoke(CurrentLocation, LastLocation); LocationUpdatedRaw?.Invoke(CurrentLocationRaw, LastLocationRaw); }
public void UpdateFilter() { System.Console.WriteLine($"Location Filter updated to display related locations"); LocationUpdated?.Invoke(this, EventArgs.Empty); }
/// <summary> /// 实现位置监听,实时缓存我的位置 /// </summary> /// <param name="location"></param> public void OnReceiveLocation(BDLocation location) { if (stopped) { return; } System.Diagnostics.Debug.WriteLine("LocType: " + location.LocType); switch (location.LocType) { default: break; case BDLocation.TypeServerError: { System.Diagnostics.Debug.Print("服务端网络定位失败,可以反馈IMEI号和大体定位时间到[email protected],会有人追查原因"); } break; case BDLocation.TypeNetWorkException: { System.Diagnostics.Debug.Print("网络不同导致定位失败,请检查网络是否通畅"); } break; case BDLocation.TypeCriteriaException: { System.Diagnostics.Debug.Print("无法获取有效定位依据导致定位失败,一般是由于手机的原因,处于飞行模式下一般会造成这种结果,可以试着重启手机"); } break; case BDLocation.TypeGpsLocation: case BDLocation.TypeNetWorkLocation: case BDLocation.TypeOffLineLocation: { StringBuilder sb = new StringBuilder(); sb.Append("time : "); sb.Append(location.Time); sb.Append("\nerror code : "); sb.Append(location.LocType); sb.Append("\nlatitude : "); sb.Append(location.Latitude); sb.Append("\nlontitude : "); sb.Append(location.Longitude); sb.Append("\nradius : "); sb.Append(location.Radius); System.Diagnostics.Debug.Print(sb.ToString()); BMap.MyLocationData loc = new BMap.MyLocationData.Builder() .Accuracy(location.Radius) .Direction(location.Direction) .Latitude(location.Latitude) .Longitude(location.Longitude) .Build(); mapView.Map.SetMyLocationData(loc); ///位置更新 LocationUpdated?.Invoke(this, new LocationUpdatedEventArgs { Coordinate = new Coordinate(loc.Latitude, loc.Longitude), Direction = location.Direction, Accuracy = location.HasRadius ? location.Radius : double.NaN, Altitude = location.HasAltitude ? location.Altitude : double.NaN, Satellites = location.SatelliteNumber, Type = location.LocTypeDescription, Province = location.Province, City = location.City, District = location.District, Street = location.Street, Address = location.AddrStr }); return; } } Failed?.Invoke(this, new LocationFailedEventArgs(location.LocType.ToString())); }
protected virtual void OnLocationUpdated() => LocationUpdated?.Invoke(this, EventArgs.Empty);
private void HandleUpdateLocation(string username, double latitude, double longitude, double?altitude) { LocationUpdated?.Invoke(this, new LocationUpdatedEventArgs(username, latitude, longitude, altitude)); }
private void OnLocationUpdated(GeoLocationData data) { LocationUpdated?.Invoke(this, new GeoLocationEventArgs(data)); }
public void RaiseEvent(UserLocation userLocation) { LocationUpdated?.Invoke(this, userLocation); }
protected void EmitLocationUpdated() { LocationUpdated?.Invoke(CurrentLocation, LastLocation); }