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);
        }
        protected void StartLocationUpdates()         //must run on UI thread
        {
            try
            {
                int interval;
                if (!(Session.InAppLocationRate is null))
                {
                    interval = (int)Session.InAppLocationRate;
                }
                else
                {
                    interval = (int)Settings.InAppLocationRate;
                }

                LocationRequest locationRequest = new LocationRequest()
                                                  .SetFastestInterval((long)(interval * 1000 * 0.8))
                                                  .SetInterval(interval * 1000);
                if (Session.LocationAccuracy == 0)
                {
                    locationRequest.SetPriority(LocationRequest.PriorityBalancedPowerAccuracy);
                }
                else
                {
                    locationRequest.SetPriority(LocationRequest.PriorityHighAccuracy);
                }
                locationCallback = new FusedLocationProviderCallback(this);
                fusedLocationProviderClient.RequestLocationUpdatesAsync(locationRequest, locationCallback);
                locationUpdating    = true;
                currentLocationRate = interval;

                CommonMethods.LogStatic("Location updates started with interval " + interval);
            }
Exemplo n.º 3
0
        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();
        }
Exemplo n.º 4
0
        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
        }
Exemplo n.º 5
0
        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)
            {
            }
        }
Exemplo n.º 6
0
        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");
            }
        }
Exemplo n.º 7
0
        public static void SetLocationTrackingEnabled(bool enabled)
        {
            if (enabled)
            {
                var request = new LocationRequest();
                request.SetInterval(20 * 1_000);
                request.SetFastestInterval(10 * 1_000);
                request.SetPriority(LocationRequest.PriorityHighAccuracy);

                //Probably not needed
                _fusedLocationProviderClient.RequestLocationUpdates(request, Callback, Looper.MainLooper);

                if (_locationPendingIntent == null)
                {
                    var intent = new Intent(mContext, typeof(LocationUpdateReceiver));
                    _locationPendingIntent =
                        PendingIntent.GetBroadcast(mContext, 123, intent, PendingIntentFlags.UpdateCurrent);
                    _fusedLocationProviderClient.RequestLocationUpdates(request, _locationPendingIntent);
                }
            }
            else
            {
                _fusedLocationProviderClient.RemoveLocationUpdates(Callback);
                _fusedLocationProviderClient.RemoveLocationUpdates(_locationPendingIntent);
                _locationPendingIntent = null;
            }

            if (MainActivity.Adapter != null)
            {
                int pos = MainActivity.Adapter.categories.FindIndex(s => s == DataHolder.LocationCategory);
                MainActivity.Adapter.NotifyItemChanged(pos);
            }
        }
Exemplo n.º 8
0
        public LocationHandler(Context context)
        {
            // Create client from context
            client = LocationServices.GetFusedLocationProviderClient(context);

            // Create Android location manager
            locationManager = context.GetSystemService(Context.LocationService) as LocationManager;

            // Create location request and set some options
            locationRequest = new LocationRequest();
            locationRequest.SetPriority(LocationRequest.PriorityHighAccuracy);
            locationRequest.SetInterval(1000);

            // Receives all location updates
            locationCallback = new LocationCallback();
            locationCallback.LocationResult += (sender, args) =>
            {
                if (args.Result == null)
                {
                    return;
                }

                foreach (var location in args.Result.Locations)
                {
                    OnLocationUpdate?.Invoke(location);
                }
            };

            // Start receiving location updates
            Start();
        }
Exemplo n.º 9
0
        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);
        }
Exemplo n.º 10
0
        public async Task <Position> GetLocationAsync()
        {
            tcsResult = new TaskCompletionSource <bool>();
            Context context = Android.App.Application.Context;

            fusedLocationProviderClient = LocationServices.GetFusedLocationProviderClient(context);
            LocationRequest locationRequest = new LocationRequest();

            //Set the location update interval (int milliseconds).
            locationRequest.SetInterval(10000);
            //Set the weight.
            locationRequest.SetPriority(LocationRequest.PriorityHighAccuracy);

            try
            {
                await fusedLocationProviderClient.RequestLocationUpdatesAsync(locationRequest, this, Looper.MainLooper);

                await tcsResult.Task;
                Log.Info(Tag, $"User Location {userLocation.Longitude},{userLocation.Latitude}");
                return(userLocation);
            }
            catch (Exception e)
            {
                Log.Error(Tag, $"GetLocationAsync exception: {e.Message}");
            }

            return(null);
        }
Exemplo n.º 11
0
 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);
     }
 }
Exemplo n.º 12
0
 /// <summary>
 /// Creates the location request.
 /// </summary>
 private void createLocationRequest()
 {
     locationRequest = LocationRequest.Create();                       //create a new location request
     locationRequest.SetPriority(LocationRequest.PriorityHighAccuracy) //set the location request priority to high
     .SetInterval(1000)                                                //set the interval for location updates to every minute
     .SetFastestInterval(1000);                                        //set the fastest interval for location updates to every second
 }
Exemplo n.º 13
0
        //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
            }
        }
Exemplo n.º 14
0
        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;
        }
Exemplo n.º 15
0
        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");
                }
            };
        }
Exemplo n.º 16
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.activity_huaweilocation);
            //Button click listeners
            FindViewById(Resource.Id.location_requestLocationUpdatesWithCallback).SetOnClickListener(this);
            FindViewById(Resource.Id.location_removeLocationUpdatesWithcallback).SetOnClickListener(this);


            AddLogFragment();

            mFusedLocationProviderClient = LocationServices.GetFusedLocationProviderClient(this);
            mSettingsClient  = LocationServices.GetSettingsClient(this);
            mLocationRequest = new LocationRequest();
            // Sets the interval for location update (unit: Millisecond)
            mLocationRequest.SetInterval(5000);
            // Sets the priority
            mLocationRequest.SetPriority(LocationRequest.PriorityHighAccuracy);
            if (null == mLocationCallback)
            {
                mLocationCallback = new LocationCallbackImpl();
            }
            if (Android.Support.V4.Content.ContextCompat.CheckSelfPermission(this,
                                                                             Manifest.Permission.AccessFineLocation) != Permission.Granted &&
                Android.Support.V4.Content.ContextCompat.CheckSelfPermission(this,
                                                                             Manifest.Permission.AccessCoarseLocation) != Permission.Granted)
            {
                string[] strings =
                { Manifest.Permission.AccessFineLocation, Manifest.Permission.AccessCoarseLocation };
                ActivityCompat.RequestPermissions(this, strings, 1);
            }
        }
 /**
  * Sets the location request parameters.
  */
 void CreateLocationRequest()
 {
     LocationRequest = new LocationRequest();
     LocationRequest.SetInterval(UpdateIntervalInMilliseconds);
     LocationRequest.SetFastestInterval(FastestUpdateIntervalInMilliseconds);
     LocationRequest.SetPriority(LocationRequest.PriorityHighAccuracy);
 }
Exemplo n.º 18
0
        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");
            }
        }
Exemplo n.º 19
0
 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);
 }
Exemplo n.º 21
0
        public void OnConnected(Bundle connectionHint)
        {
            mLocationRequest = LocationRequest.Create();
            mLocationRequest.SetPriority(LocationRequest.PriorityHighAccuracy);
            mLocationRequest.SetInterval(1000);

            Models.DebugUtil.WriteLine("[Droid] GoogleApiClient > OnConnected");
        }
Exemplo n.º 22
0
 void BuildLocationRequest()
 {
     LocationRequest1 = new LocationRequest();
     LocationRequest1.SetPriority(LocationRequest.PriorityHighAccuracy);
     LocationRequest1.SetInterval(5000);
     LocationRequest1.SetFastestInterval(3000);
     LocationRequest1.SetSmallestDisplacement(10f);
 }
Exemplo n.º 23
0
 private static void LocationReqvest()
 {
     locationRequest = new LocationRequest();
     locationRequest.SetPriority(LocationRequest.PriorityHighAccuracy);
     locationRequest.SetInterval(100);
     locationRequest.SetFastestInterval(50);
     locationRequest.SetSmallestDisplacement(1);
 }
Exemplo n.º 24
0
 private void BuildLocationRequest()
 {
     locationRequest = new LocationRequest();
     locationRequest.SetPriority(LocationRequest.PriorityBalancedPowerAccuracy);
     locationRequest.SetInterval(1000);
     locationRequest.SetFastestInterval(3000);
     locationRequest.SetSmallestDisplacement(10f);
 }
Exemplo n.º 25
0
 private void BuildLocationRequest()
 {
     locationRequest = new LocationRequest();
     locationRequest.SetPriority(LocationRequest.PriorityHighAccuracy);
     locationRequest.SetInterval(8000);
     locationRequest.SetFastestInterval(6000);
     locationRequest.SetSmallestDisplacement(10f);
 }
Exemplo n.º 26
0
 private void CreateLocationRequest()
 {
     mLocationRequest = new LocationRequest();
     mLocationRequest.SetInterval(UPDATE_INTERVAL);
     mLocationRequest.SetFastestInterval(FATEST_INTERVAL);
     mLocationRequest.SetPriority(LocationRequest.PriorityHighAccuracy);
     mLocationRequest.SetSmallestDisplacement(DISPLACEMENT);
 }
Exemplo n.º 27
0
 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);
 }
Exemplo n.º 28
0
        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");
                }
            };
        }
Exemplo n.º 29
0
        LocationRequest CreateLocationRequest(long interval)
        {
            LocationRequest locationRequest = new LocationRequest();

            locationRequest.SetPriority(100);
            locationRequest.SetFastestInterval(interval);
            locationRequest.SetInterval(interval);
            return(locationRequest);
        }
Exemplo n.º 30
0
        public LocationPresenter(Activity activity)
        {
            mLocationClient = new LocationClient(activity, this, this);

            mLocationRequest = LocationRequest.Create();
            mLocationRequest.SetPriority(LocationRequest.PriorityHighAccuracy);
            mLocationRequest.SetInterval(10 * 1000);
            mLocationRequest.SetFastestInterval(1000);
        }
Exemplo n.º 31
0
        private LocationRequest CreateLocationRequest(LocationRequestProfile profile)
        {
            var request = new LocationRequest();

            request.SetPriority(profile.Priority);
            request.SetInterval(profile.Interval);

            return(request);
        }
Exemplo n.º 32
0
        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);
        }
Exemplo n.º 33
0
		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";
				}
			};
		}
Exemplo n.º 34
0
		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");
		}
 LocationRequest CreateLocationRequest()
 {
     var locationRequest = new LocationRequest();
     locationRequest.SetSmallestDisplacement((float)smallestDisplacementMeters);
     locationRequest.SetPriority(accuracy);
     locationRequest.SetInterval(interval);
     locationRequest.SetFastestInterval(fastestInterval);
     return locationRequest;
 }
Exemplo n.º 36
0
		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);
		}
Exemplo n.º 37
0
		protected void CreateLocationRequest ()
		{
			mLocationRequest = new LocationRequest ();

			mLocationRequest.SetInterval (UPDATE_INTERVAL_IN_MILLISECONDS);

			mLocationRequest.SetFastestInterval (FASTEST_UPDATE_INTERVAL_IN_MILLISECONDS);

			mLocationRequest.SetPriority (LocationRequest.PriorityHighAccuracy);
		}
        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();
        }
        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);
                } 
            });
        }
Exemplo n.º 40
0
 private void InitalizeGoogleLocationSettingsRequest()
 {
     _googleLocationRequest = new LocationRequest();
     _googleLocationRequest.SetInterval(UPDATE_INTERVAL_IN_MILLISECONDS);
     _googleLocationRequest.SetFastestInterval(FASTEST_UPDATE_INTERVAL_IN_MILLISECONDS);
     _googleLocationRequest.SetPriority(LocationRequest.PriorityHighAccuracy);
 }