public override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); LocHandler = new LocationHandler(Activity.GetSystemService(Activity.LocationService) as LocationManager); LocHandler.LocationRequest += (sender, args) => { if (args == LocationHandler.messageType.LOCATION) { // sets the location initially var loc = (Location)sender; if (followPosition) { lastPosition = loc; SetLocation(loc.Latitude, loc.Longitude); } } else if (args == LocationHandler.messageType.DISABLED) { Toast.MakeText(Activity, Resource.String.ENABLE_GPS, ToastLength.Long).Show(); } else if (args == LocationHandler.messageType.ENABLED) { Log.Debug("GPSPROVIDER", "Enabled"); } }; // initializes the LocationHandler and fires an event if any porblems occur LocHandler.Init(); }
// Activates the location listener // distance: enforces to set a minimum distance that must be reached before the places api will be requested public void ActivateLocationChangeRequests(Activity Activity,float distance) { LocHandler = new LocationHandler(Activity.GetSystemService(Activity.LocationService) as LocationManager); LocHandler.LocationRequest += async (sender, args) => { if (args == LocationHandler.messageType.LOCATION) { // sets the location initially var loc = (Location)sender; var calcDist = double.MaxValue; if(lastPosition != null) { calcDist = LatLngDist.distance(loc.Latitude, loc.Longitude, lastPosition.Latitude, lastPosition.Longitude, 'K'); } if (distance < calcDist) { JsonValue x = await GetPlacesAsJSON(loc.Latitude, loc.Longitude, 200); var handler = PlacesResponse; if (handler != null) { handler(x, EventArgs.Empty); } lastPosition = loc; } } else if (args == LocationHandler.messageType.DISABLED) { Toast.MakeText(Activity, Resource.String.ENABLE_GPS, ToastLength.Long).Show(); } }; // initializes the LocationHandler and fires an event if any porblems occur LocHandler.Init(); }