void InitSensor() { locationManager = Application.Context.GetSystemService(Context.LocationService) as LocationManager; DeviceDebugAndroid.LogToFileStatic("gps sensor requested"); if (locationManager != null) { if (locationManager.IsProviderEnabled(LocationManager.GpsProvider)) { locationManager.RequestLocationUpdates(LocationManager.GpsProvider, 0, 0, this); locationManager.AddGpsStatusListener(this); location = locationManager.GetLastKnownLocation(LocationManager.GpsProvider); status = IDeviceGpsStatus.Requested; DeviceDebugAndroid.LogToFileStatic("gps sensor init ok"); } else { status = IDeviceGpsStatus.Disabled; DeviceDebugAndroid.LogToFileStatic("ERROR: gps sensor not enabled"); } } else { status = IDeviceGpsStatus.Disabled; DeviceDebugAndroid.LogToFileStatic("ERROR: gps locationManager is null"); } }
protected override void OnResume() { try { this.logDebug(LogLevel.Verbose, "Entering OnResume"); lastGpsEvent_debug = GpsEvent.Stopped; base.OnResume(); logDebug(LogLevel.Verbose, "RESUMED"); LocationManager lm = (LocationManager)GetSystemService(Context.LocationService); lm.AddGpsStatusListener(this); if (updateReadiness()) // gps could be switched meanwhile { showAlarm("running", Android.Graphics.Color.GreenYellow); ServiceReceiver.SendInfoRequest(this); } this.logDebug(LogLevel.Verbose, "Done OnResume"); } catch (Exception ex) { this.logDebug(LogLevel.Error, "OnResume " + ex.ToString()); } }
public void Init() { var criteriaForLocationService = new Criteria { Accuracy = Accuracy.Fine, HorizontalAccuracy = Accuracy.Fine, VerticalAccuracy = Accuracy.Fine, PowerRequirement = Power.NoRequirement, SpeedRequired = true, SpeedAccuracy = Accuracy.Fine }; _providerName = _locationManager.GetBestProvider(criteriaForLocationService, false); if (_providerName != null) { _locationManager.RequestLocationUpdates(_providerName, 0, minDistance, this); var lastLocation = _locationManager.GetLastKnownLocation(_providerName); OnLocationChanged(lastLocation); } _locationManager.AddGpsStatusListener(this); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); // Get our button from the layout resource, // and attach an event to it Button button = FindViewById <Button>(Resource.Id.MyButton); locationManager = (LocationManager)GetSystemService(Context.LocationService); locationManager.AddGpsStatusListener(this); locationManager.RequestLocationUpdates(LocationManager.GpsProvider, 0, 0, this); GpsStatus gpsStatus = locationManager.GetGpsStatus(null); if (gpsStatus != null) { IIterable satellites = gpsStatus.Satellites; IIterator sat = satellites.Iterator(); string lSatellites = null; int i = 0; while (sat.HasNext) { GpsSatellite satellite = sat.Next().JavaCast <GpsSatellite>(); Debug.WriteLine(satellite.Prn); } } button.Click += delegate { button.Text = string.Format("{0} clicks!", count++); }; }