internal void StartLocationUpdates() { LocationRequest mLocationRequest = new LocationRequest(); mLocationRequest.SetInterval(CrossGeofence.LocationUpdatesInterval == 0 ? 30000 : CrossGeofence.LocationUpdatesInterval); mLocationRequest.SetFastestInterval(CrossGeofence.FastestLocationUpdatesInterval == 0 ? 5000 : CrossGeofence.FastestLocationUpdatesInterval); string priorityType="Balanced Power"; switch(CrossGeofence.GeofencePriority) { case GeofencePriority.HighAccuracy: priorityType="High Accuracy"; mLocationRequest.SetPriority(LocationRequest.PriorityHighAccuracy); break; case GeofencePriority.LowAccuracy: priorityType="Low Accuracy"; mLocationRequest.SetPriority(LocationRequest.PriorityLowPower); break; case GeofencePriority.LowestAccuracy: priorityType="Lowest Accuracy"; mLocationRequest.SetPriority(LocationRequest.PriorityNoPower); break; case GeofencePriority.MediumAccuracy: case GeofencePriority.AcceptableAccuracy: default: mLocationRequest.SetPriority(LocationRequest.PriorityBalancedPowerAccuracy); break; } Debug.WriteLine("{0} - {1}: {2}", CrossGeofence.Id, "Priority set to", priorityType); //(Regions.Count == 0) ? (CrossGeofence.SmallestDisplacement==0?50 :CrossGeofence.SmallestDisplacement): Regions.Min(s => (float)s.Value.Radius) if(CrossGeofence.SmallestDisplacement>0) { mLocationRequest.SetSmallestDisplacement(CrossGeofence.SmallestDisplacement); Debug.WriteLine("{0} - {1}: {2} meters", CrossGeofence.Id, "Location smallest displacement set to", CrossGeofence.SmallestDisplacement); } LocationServices.FusedLocationApi.RequestLocationUpdates(mGoogleApiClient, mLocationRequest, GeofenceLocationListener.SharedInstance); }
void GPS_StatusChange() { try { if (_locationService is null) { _locationManager = (LocationManager)GetSystemService(Context.LocationService); Criteria criteriaForLocationService = new Criteria { Accuracy = Accuracy.Fine }; IList <string> acceptableLocationProviders = _locationManager.GetProviders(criteriaForLocationService, true); if (acceptableLocationProviders.Any()) { _locationManager.RequestLocationUpdates(acceptableLocationProviders.First(), 0, 0, this); } _locationService = LocationServices.GetFusedLocationProviderClient(this); var locationRequest = new LocationRequest(); locationRequest.SetInterval(180000); locationRequest.SetFastestInterval(90000); locationRequest.SetPriority(LocationRequest.PriorityHighAccuracy); _providerCallback = new FusedLocationProviderCallback(); _locationService.RequestLocationUpdates(locationRequest, _providerCallback, Looper.MyLooper()); } } catch (Exception e) { //Crashes.TrackError(e); } }
private void CreateLocationRequest() { locRequest = new LocationRequest(); locRequest.SetInterval(5000); locRequest.SetFastestInterval(4000); locRequest.SetPriority(LocationRequest.PriorityHighAccuracy); }
protected void CreateLocationRequest() { mLocationRequest = new LocationRequest(); mLocationRequest.SetInterval(UPDATE_INTERVAL_IN_MILLISECONDS); mLocationRequest.SetFastestInterval(FASTEST_UPDATE_INTERVAL_IN_MILLISECONDS); mLocationRequest.SetPriority(LocationRequest.PriorityHighAccuracy); }
private void RequestUpdateLocations() { if (apiClient.IsConnected) { // Setting location priority to PRIORITY_HIGH_ACCURACY (100) locRequest.SetPriority(100); // Setting interval between updates, in milliseconds // NOTE: the default FastestInterval is 1 minute. If you want to receive location updates more than // once a minute, you _must_ also change the FastestInterval to be less than or equal to your Interval locRequest.SetFastestInterval(500); locRequest.SetInterval(1000); Log.Debug("LocationRequest", "Request priority set to status code {0}, interval set to {1} ms", locRequest.Priority.ToString(), locRequest.Interval.ToString()); // pass in a location request and LocationListener LocationServices.FusedLocationApi.RequestLocationUpdates(apiClient, locRequest, this); // In OnLocationChanged (below), we will make calls to update the UI // with the new location data } else { Log.Info("LocationClient", "Please wait for Client to connect"); } }
private LocationRequest GetLocationRequest() { var locationRequestPriority = LocationRequest.PriorityBalancedPowerAccuracy; switch (CrossGeofence.GeofencePriority) { case GeofencePriority.HighAccuracy: locationRequestPriority = LocationRequest.PriorityHighAccuracy; break; case GeofencePriority.LowAccuracy: locationRequestPriority = LocationRequest.PriorityLowPower; break; case GeofencePriority.LowestAccuracy: locationRequestPriority = LocationRequest.PriorityNoPower; break; } var locationRequest = new LocationRequest(); locationRequest.SetPriority(locationRequestPriority); locationRequest.SetInterval(CrossGeofence.LocationUpdatesInterval); locationRequest.SetFastestInterval(CrossGeofence.FastestLocationUpdatesInterval); return(locationRequest); }
public void OnConnected(Bundle bundle) { // This method is called when we connect to the LocationClient. We can start location updated directly form // here if desired, or we can do it in a lifecycle method, as shown above // You must implement this to implement the IGooglePlayServicesClientConnectionCallbacks Interface Log.Info("LocationClient", "Now connected to client"); // Setting location priority to PRIORITY_HIGH_ACCURACY (100) locRequest.SetPriority(100); // Setting interval between updates, in milliseconds // NOTE: the default FastestInterval is 1 minute. If you want to receive location updates more than // once a minute, you _must_ also change the FastestInterval to be less than or equal to your Interval locRequest.SetFastestInterval(500); locRequest.SetInterval(1000); Log.Debug("LocationRequest", "Request priority set to status code {0}, interval set to {1} ms", locRequest.Priority.ToString(), locRequest.Interval.ToString()); // pass in a location request and LocationListener LocationServices.FusedLocationApi.RequestLocationUpdates(locClient, locRequest, this); // In OnLocationChanged (below), we will make calls to update the UI // with the new location data }
public void Initalize() { Log.Info("MainActivity", "Google Play Services is installed on this device."); apiClient = new GoogleApiClient.Builder(this, this, this) .AddApi(LocationServices.API).Build(); // generate a location request that we will pass into a call for location updates locRequest = new LocationRequest(); locRequest.SetPriority(100); // Setting interval between updates, in milliseconds // NOTE: the default FastestInterval is 1 minute. If you want to receive location updates more than // once a minute, you _must_ also change the FastestInterval to be less than or equal to your Interval locRequest.SetFastestInterval(500); locRequest.SetInterval(1000); // setting up the time sendUpdateTimer = new System.Timers.Timer(AppConfig.PostInterval * 1000); sendUpdateTimer.AutoReset = false; sendUpdateTimer.Elapsed += (sender, e) => onPostInterval(sender, e); // Map of sensor details sensorDetailMap = new Dictionary <string, SensorDetail>(); // Broadcast re receiver = new SensorReadingBroadcastReceiver(); receiver.OnSensorReading += (sender, e) => onNewSensor(sender, e); // location rec locationReceiver = new LocationBroadcastReceiver(); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); // Get controls: _addressButton = FindViewById <Button>(Resource.Id.MyButton); _locationsListView = FindViewById <ListView>(Resource.Id.LocationsListView); _addressButton.Text = "Location updating paused. Tap to start."; if (_googleApiClient == null) { _googleApiClient = new Builder(Application.Context, this, this) .AddApi(LocationServices.API) .Build(); } _locRequest = new LocationRequest(); _locRequest.SetPriority(LocationRequest.PriorityHighAccuracy); _locRequest.SetInterval(2000); _locRequest.SetFastestInterval(1000); // Get our button from the layout resource, // and attach an event to it _addressButton.Click += AddressButton_OnClick; _locationsListViewAdapter = new ArrayAdapter <string>(this, Android.Resource.Layout.SimpleExpandableListItem1, _locationsListViewData); _locationsListView.Adapter = _locationsListViewAdapter; }
/** * Sets the location request parameters. */ void CreateLocationRequest() { LocationRequest = new LocationRequest(); LocationRequest.SetInterval(UpdateIntervalInMilliseconds); LocationRequest.SetFastestInterval(FastestUpdateIntervalInMilliseconds); LocationRequest.SetPriority(LocationRequest.PriorityHighAccuracy); }
public async void turnOnGps() { try { MainActivity activity = global::Xamarin.Forms.Forms.Context as MainActivity; GoogleApiClient googleApiClient = new GoogleApiClient.Builder(activity).AddApi(LocationServices.API).Build(); googleApiClient.Connect(); LocationRequest locationRequest = LocationRequest.Create(); locationRequest.SetPriority(LocationRequest.PriorityHighAccuracy); locationRequest.SetInterval(10000); locationRequest.SetFastestInterval(10000 / 2); LocationSettingsRequest.Builder locationSettingsRequestBuilder = new LocationSettingsRequest.Builder().AddLocationRequest(locationRequest); locationSettingsRequestBuilder.SetAlwaysShow(false); LocationSettingsResult locationSettingsResult = await LocationServices.SettingsApi.CheckLocationSettingsAsync( googleApiClient, locationSettingsRequestBuilder.Build()); if (locationSettingsResult.Status.StatusCode == LocationSettingsStatusCodes.ResolutionRequired) { locationSettingsResult.Status.StartResolutionForResult(activity, 0); } var result = await LocationServices.SettingsApi.CheckLocationSettingsAsync(googleApiClient, locationSettingsRequestBuilder.Build()); } catch (Exception ex) { } }
public GpsApiClient(Android.Content.Context context, bool useInterval) { _useInterval = useInterval; CheckSetGooglePlayServicesInstalled(context); if (IsGooglePlayServicesInstalled) { // pass in the Context, ConnectionListener and ConnectionFailedListener _apiClient = new GoogleApiClient.Builder(context, this, this).AddApi(LocationServices.API).Build(); _locRequest = new LocationRequest(); if (useInterval) { _locRequest.SetPriority(100); _locRequest.SetFastestInterval(500); _locRequest.SetInterval(1000); Log.Debug("GpsApiClient", "Request priority set to status code {0}, interval set to {1} ms", _locRequest.Priority.ToString(), _locRequest.Interval.ToString()); } _apiClient.Connect(); } else { Log.Error(CLIENT_LOG_NAME, "Google Play Services is not installed"); } }
//This procedure calls //not sure if im calling this right. //1) is it OK to pass in mainactivity like this? //2) any way to get a callback after they enable? (ie, to reload webview) //3) any way to delay the initial load of the webview until they hit the OK button to load fixity? //https://forums.xamarin.com/discussion/118189/gps-location-enable-in-xamarin-forms //https://stackoverflow.com/questions/33251373/turn-on-location-services-without-navigating-to-settings-page //https://stackoverflow.com/questions/43138788/ask-user-to-turn-on-location/43139125 //https://forums.xamarin.com/discussion/140325/how-to-check-every-time-for-gps-connectivity (code based on this) public async void turnOnGps(MainActivity activity) { try { //MainActivity activity = Xamarin.Forms.Context as MainActivity; GoogleApiClient googleApiClient = new GoogleApiClient.Builder(activity) .AddApi(LocationServices.API).Build(); googleApiClient.Connect(); LocationRequest locationRequest = LocationRequest.Create(); locationRequest.SetPriority(LocationRequest.PriorityHighAccuracy); locationRequest.SetInterval(10000); locationRequest.SetFastestInterval(10000 / 2); LocationSettingsRequest.Builder locationSettingsRequestBuilder = new LocationSettingsRequest.Builder() .AddLocationRequest(locationRequest); locationSettingsRequestBuilder.SetAlwaysShow(false); LocationSettingsResult locationSettingsResult = await LocationServices.SettingsApi.CheckLocationSettingsAsync( googleApiClient, locationSettingsRequestBuilder.Build()); if (locationSettingsResult.Status.StatusCode == LocationSettingsStatusCodes.ResolutionRequired) { locationSettingsResult.Status.StartResolutionForResult(activity, 0); } } catch (Java.Lang.Exception ex) { Xamarin.Forms.DependencyService.Get <IMessage>().LongAlert(ex.Message); //show error } }
protected override void OnResume() { base.OnResume(); Log.Debug("OnResume", "OnResume called, connecting to client..."); apiClient.Connect(); // Clicking the second button will send a request for continuous updates button2.Click += async delegate { if (apiClient.IsConnected) { button2.Text = "Requesting Location Updates"; // Setting location priority to PRIORITY_HIGH_ACCURACY (100) locRequest.SetPriority(100); // Setting interval between updates, in milliseconds // NOTE: the default FastestInterval is 1 minute. If you want to receive location updates more than // once a minute, you _must_ also change the FastestInterval to be less than or equal to your Interval locRequest.SetFastestInterval(500); locRequest.SetInterval(1000); // pass in a location request and LocationListener await LocationServices.FusedLocationApi.RequestLocationUpdates(apiClient, locRequest, this); // In OnLocationChanged (below), we will make calls to update the UI // with the new location data } else { Log.Info("LocationClient", "Please wait for Client to connect"); } }; }
private void CreateLocationRequest() { mLocationRequest = new LocationRequest(); mLocationRequest.SetInterval(UPDATE_INTERVAL); mLocationRequest.SetFastestInterval(FATEST_INTERVAL); mLocationRequest.SetPriority(LocationRequest.PriorityHighAccuracy); mLocationRequest.SetSmallestDisplacement(DISPLACEMENT); }
private void BuildLocationRequest() { locationRequest = new LocationRequest(); locationRequest.SetPriority(LocationRequest.PriorityHighAccuracy); locationRequest.SetInterval(8000); locationRequest.SetFastestInterval(6000); locationRequest.SetSmallestDisplacement(10f); }
private static void LocationReqvest() { locationRequest = new LocationRequest(); locationRequest.SetPriority(LocationRequest.PriorityHighAccuracy); locationRequest.SetInterval(100); locationRequest.SetFastestInterval(50); locationRequest.SetSmallestDisplacement(1); }
private void BuildLocationRequest() { locationRequest = new LocationRequest(); locationRequest.SetPriority(LocationRequest.PriorityBalancedPowerAccuracy); locationRequest.SetInterval(1000); locationRequest.SetFastestInterval(3000); locationRequest.SetSmallestDisplacement(10f); }
private void InitLocationServices() { _googleApiClient = new GoogleApiClient.Builder(this, this, this).AddApi(LocationServices.API).Build(); _locationRequest = LocationRequest.Create(); _locationRequest.SetPriority(LocationRequest.PriorityHighAccuracy); _locationRequest.SetInterval(LocationRequestInterval); _locationRequest.SetFastestInterval(LocationRequestFastestInterval); }
void BuildLocationRequest() { LocationRequest1 = new LocationRequest(); LocationRequest1.SetPriority(LocationRequest.PriorityHighAccuracy); LocationRequest1.SetInterval(5000); LocationRequest1.SetFastestInterval(3000); LocationRequest1.SetSmallestDisplacement(10f); }
protected override void OnResume() { base.OnResume(); Log.Debug("OnResume", "OnResume called, connecting to client..."); locClient.Connect(); // Clicking the first button will make a one-time call to get the user's last location button.Click += delegate { if (locClient.IsConnected) { button.Text = "Getting Last Location"; if (locClient.LastLocation != null) { Location location = locClient.LastLocation; latitude.Text = "Latitude: " + location.Latitude.ToString(); longitude.Text = "Longitude: " + location.Longitude.ToString(); provider.Text = "Provider: " + location.Provider.ToString(); Log.Debug("LocationClient", "Last location printed"); } } else { Log.Info("LocationClient", "Please wait for client to connect"); } }; // Clicking the second button will send a request for continuous updates button2.Click += delegate { if (locClient.IsConnected) { button2.Text = "Requesting Location Updates"; // Setting location priority to PRIORITY_HIGH_ACCURACY (100) locRequest.SetPriority(100); // Setting interval between updates, in milliseconds // NOTE: the default FastestInterval is 1 minute. If you want to receive location updates more than // once a minute, you _must_ also change the FastestInterval to be less than or equal to your Interval locRequest.SetFastestInterval(500); locRequest.SetInterval(1000); Log.Debug("LocationRequest", "Request priority set to status code {0}, interval set to {1} ms", locRequest.Priority.ToString(), locRequest.Interval.ToString()); // pass in a location request and LocationListener locClient.RequestLocationUpdates(locRequest, this); // In OnLocationChanged (below), we will make calls to update the UI // with the new location data } else { Log.Info("LocationClient", "Please wait for Client to connect"); } }; }
public LocationPresenter(Activity activity) { mLocationClient = new LocationClient(activity, this, this); mLocationRequest = LocationRequest.Create(); mLocationRequest.SetPriority(LocationRequest.PriorityHighAccuracy); mLocationRequest.SetInterval(10 * 1000); mLocationRequest.SetFastestInterval(1000); }
void CreateLocationRequest() { mLocationRequest = new LocationRequest(); mLocationRequest.SetInterval(UPDATE_INTERVAL); mLocationRequest.SetFastestInterval(FASTEST_INTERVAL); mLocationRequest.SetPriority(LocationRequest.PriorityHighAccuracy); mLocationRequest.SetSmallestDisplacement(DISPLACEMENT); locationClient = LocationServices.GetFusedLocationProviderClient(this); }
private LocationRequest CreateLocationRequest() { var locationRequest = new LocationRequest(); locationRequest.SetInterval(1000); locationRequest.SetFastestInterval(1000); locationRequest.SetPriority(LocationRequest.PriorityHighAccuracy); return(locationRequest); }
LocationRequest CreateLocationRequest(long interval) { LocationRequest locationRequest = new LocationRequest(); locationRequest.SetPriority(100); locationRequest.SetFastestInterval(interval); locationRequest.SetInterval(interval); return(locationRequest); }
public void OnConnected(Bundle connectionHint) { Console.WriteLine("Connected to client"); locRequest.SetPriority(100); locRequest.SetFastestInterval(500); locRequest.SetInterval(1000); LocationServices.FusedLocationApi.RequestLocationUpdates(apiClient, locRequest, this); }
void CreateLocationRequest() { mLocationRequest = new LocationRequest(); mLocationRequest.SetInterval(IntegerConstants.GetUpdateInterval()); mLocationRequest.SetFastestInterval(IntegerConstants.GetFastestInterval()); mLocationRequest.SetPriority(LocationRequest.PriorityHighAccuracy); mLocationRequest.SetSmallestDisplacement(IntegerConstants.GetDisplacement()); locationProviderClient = LocationServices.GetFusedLocationProviderClient(Activity); CheckLocationSettings(); }
public void OnConnected ( Bundle connectionHint ) { Log.Debug (TAG, "OnConnected"); _locationRequest = LocationRequest.Create (); _locationRequest.SetInterval (1000); _locationRequest.SetFastestInterval (1000); _locationRequest.SetPriority (LocationRequest.PriorityHighAccuracy); LocationServices.FusedLocationApi.RequestLocationUpdates (_googleApiClient, _locationRequest, this); }
void CreateLocationRequest() { mLocationRequest = new LocationRequest(); mLocationRequest.SetInterval(UPDATE_INTERVAL); mLocationRequest.SetFastestInterval(FAST_INTERVAL); mLocationRequest.SetPriority(LocationRequest.PriorityHighAccuracy); mLocationRequest.SetSmallestDisplacement(DISPACEMENT); mLocationCallback.MyLocation += MLocationCallback_MyLocation; LocationProviderClient = LocationServices.GetFusedLocationProviderClient(Activity); }
public void OnConnected(Bundle connectionHint) { LocationRequest locRequest = new LocationRequest(); locRequest.SetPriority(100); locRequest.SetFastestInterval(500); locRequest.SetInterval(1000); LocationServices.FusedLocationApi.RequestLocationUpdates(_googleApiClient, locRequest, this); }
public async Task ChangeInterval(int miliseconds = 1000 * 60 * 30) { if (_locationRequest != null && _fusedLocationProviderClient != null) { _locationRequest.SetFastestInterval(miliseconds); _locationRequest.SetInterval(miliseconds); _locationRequest.SetMaxWaitTime(miliseconds + 10000); await RequestLocationUpdates(); } }
public void OnConnected(Bundle connectionHint) { Log.Debug(TAG, "OnConnected"); _locationRequest = LocationRequest.Create(); _locationRequest.SetInterval(1000); _locationRequest.SetFastestInterval(1000); _locationRequest.SetPriority(LocationRequest.PriorityHighAccuracy); LocationServices.FusedLocationApi.RequestLocationUpdates(_googleApiClient, _locationRequest, this); }
protected override void OnCreate (Bundle savedInstanceState) { base.OnCreate (savedInstanceState); // Set our view from the "main" layout resource SetContentView (Resource.Layout.Main); // Set up Google Play location service apiClient = new GoogleApiClient.Builder (this, this, this) .AddApi (LocationServices.API).Build (); apiClient.Connect (); lastLocationButton = FindViewById<Button> (Resource.Id.lastLocationButton); locationTextView = FindViewById<TextView> (Resource.Id.locationTextView); // Clicking the button will make a one-time call to get the device's last known location lastLocationButton.Click += delegate { Android.Locations.Location location = LocationServices.FusedLocationApi.GetLastLocation (apiClient); locationTextView.Text = "Last location:\n"; DisplayLocation(location); }; locationUpdateButton = FindViewById<Button> (Resource.Id.locationUpdateButton); // Clicking the button will send a request for continuous updates locationUpdateButton.Click += async delegate { if (apiClient.IsConnected) { locationTextView.Text = "Requesting Location Updates"; var locRequest = new LocationRequest(); // Setting location priority to PRIORITY_HIGH_ACCURACY (100) locRequest.SetPriority(100); // Setting interval between updates, in milliseconds // NOTE: the default FastestInterval is 1 minute. If you want to receive location updates more than // once a minute, you _must_ also change the FastestInterval to be less than or equal to your Interval locRequest.SetFastestInterval(500); locRequest.SetInterval(1000); // pass in a location request and LocationListener await LocationServices.FusedLocationApi.RequestLocationUpdates (apiClient, locRequest, this); // In OnLocationChanged (below), we will make calls to update the UI // with the new location data } else { locationTextView.Text = "Client API not connected"; } }; }
public LocationProvider (Activity context) { Context = context; //apiClient = new GoogleApiClient.Builder (Android.App.Application.Context, this, this).AddApi (LocationServices.API).Build (); apiClient = new GoogleApiClient.Builder (Android.App.Application.Context, this, this).AddApi (LocationServices.API).Build (); locRequest = LocationRequest.Create (); // Setting location priority to PRIORITY_HIGH_ACCURACY (100) locRequest.SetPriority (100); // Setting interval between updates, in milliseconds // NOTE: the default FastestInterval is 1 minute. If you want to receive location updates more than // once a minute, you _must_ also change the FastestInterval to be less than or equal to your Interval locRequest.SetFastestInterval (500); locRequest.SetInterval (1000); WriteLine ($"Request priority set to status code {locRequest.Priority}, interval set to {locRequest.Interval} ms"); }
protected void CreateLocationRequest () { mLocationRequest = new LocationRequest (); mLocationRequest.SetInterval (UPDATE_INTERVAL_IN_MILLISECONDS); mLocationRequest.SetFastestInterval (FASTEST_UPDATE_INTERVAL_IN_MILLISECONDS); mLocationRequest.SetPriority (LocationRequest.PriorityHighAccuracy); }
public void OnConnected (Bundle connectionHint) { Console.WriteLine ("Connected to Google services"); var locationRequest = new LocationRequest (); locationRequest.SetPriority (100); locationRequest.SetFastestInterval (2000); locationRequest.SetInterval (5000); LocationServices.FusedLocationApi.RequestLocationUpdates (_googleApiClient, locationRequest, this); }
private void InitalizeGoogleLocationSettingsRequest() { _googleLocationRequest = new LocationRequest(); _googleLocationRequest.SetInterval(UPDATE_INTERVAL_IN_MILLISECONDS); _googleLocationRequest.SetFastestInterval(FASTEST_UPDATE_INTERVAL_IN_MILLISECONDS); _googleLocationRequest.SetPriority(LocationRequest.PriorityHighAccuracy); }
public void OnConnected(Bundle bundle) { LocationClientConnected = true; var locationRequest = new LocationRequest (); locationRequest.SetInterval (5000); locationRequest.SetFastestInterval (1000); LocationClient.RequestLocationUpdates (locationRequest, this); if (MapViewFragment != null) MapViewFragment.FlyDownToMyLocation (); }
public void IsLocationEnabled(Action<bool> returnAction) { InitializeGoogleAPI(); var locationRequestPriority = LocationRequest.PriorityBalancedPowerAccuracy; switch (CrossGeofence.GeofencePriority) { case GeofencePriority.HighAccuracy: locationRequestPriority = LocationRequest.PriorityHighAccuracy; break; case GeofencePriority.LowAccuracy: locationRequestPriority = LocationRequest.PriorityLowPower; break; case GeofencePriority.LowestAccuracy: locationRequestPriority = LocationRequest.PriorityNoPower; break; } var locationRequest = new LocationRequest(); locationRequest.SetPriority(locationRequestPriority); locationRequest.SetInterval(CrossGeofence.LocationUpdatesInterval); locationRequest.SetFastestInterval(CrossGeofence.FastestLocationUpdatesInterval); LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder().AddLocationRequest(locationRequest); var pendingResult = LocationServices.SettingsApi.CheckLocationSettings(mGoogleApiClient, builder.Build()); pendingResult.SetResultCallback((LocationSettingsResult locationSettingsResult) => { if (locationSettingsResult != null) { returnAction(locationSettingsResult.Status.StatusCode <= CommonStatusCodes.Success); } }); }
LocationRequest CreateLocationRequest() { var locationRequest = new LocationRequest(); locationRequest.SetSmallestDisplacement((float)smallestDisplacementMeters); locationRequest.SetPriority(accuracy); locationRequest.SetInterval(interval); locationRequest.SetFastestInterval(fastestInterval); return locationRequest; }
protected override void PlatformSpecificStart(MvxLocationOptions options) { if (_googleApiClient != null) throw new MvxException("You cannot start MvxLocation service more than once"); if (GooglePlayServicesUtil.IsGooglePlayServicesAvailable(Context) != ConnectionResult.Success) throw new MvxException("Google Play Services are not available"); _locationRequest = LocationRequest.Create(); _locationRequest.SetInterval((long)options.TimeBetweenUpdates.TotalMilliseconds); _locationRequest.SetSmallestDisplacement(options.MovementThresholdInM); _locationRequest.SetFastestInterval(1000); _locationRequest.SetPriority(options.Accuracy == MvxLocationAccuracy.Fine ? LocationRequest.PriorityHighAccuracy : LocationRequest.PriorityBalancedPowerAccuracy); _googleApiClient = new GoogleApiClient.Builder(this.Context) .AddApi(LocationServices.API) .AddConnectionCallbacks(_connectionCallBacks) .AddOnConnectionFailedListener(_connectionFailed) .Build(); //_locationClient = new LocationClient(Context, _connectionCallBacks, _connectionFailed); //_locationClient.Connect(); _googleApiClient.Connect(); }