示例#1
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);
            }
        }
示例#2
0
 public void OnSuccess(Java.Lang.Object p0)
 {
     Toast.MakeText(locationActivity, "Settings are checked.", ToastLength.Long).Show();
     fusedLocationProviderClient.RequestLocationUpdates(locationRequest, locationCallback, Looper.MainLooper)
     .AddOnSuccessListener(new RequestLocationCallbackOnSuccessListener(locationActivity))
     .AddOnFailureListener(new RequestLocationCallbackOnFailureListener(locationActivity));;
 }
示例#3
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);
     }
 }
示例#4
0
 private void StartLocationUpdate()
 {
     if (CheckPermission())
     {
         locationClient.RequestLocationUpdates(locationRequest, locationCallBack, null);
     }
 }
示例#5
0
 void StartLocationUpdates()
 {
     if (CheckLocationPermission())
     {
         locationClient.RequestLocationUpdates(mLocationRequest, mLocationCallback, null);
     }
 }
示例#6
0
 void StartLocationUpdate()
 {
     if (CheckLocationPermission())
     {
         locApiClient.RequestLocationUpdates(myLocRequest, myLocationCallbackHelper, null);
     }
 }
 public void OnSuccess(Java.Lang.Object locObj)
 {
     Log.Info(TAG, "check location settings success");
     mFusedLocationProviderClient
     .RequestLocationUpdates(mLocationRequest, mLocationCallback, Looper.MainLooper)
     .AddOnSuccessListener(new LocCallUpdateReqOnSuccessListenerImpl())
     .AddOnFailureListener(new LocCallUpdateReqOnFailureListenerImpl());
 }
示例#8
0
        public void StartLocationProvider()
        {
            var locationRequest = LocationRequest.Create()
                                  .SetPriority(LocationRequest.PriorityHighAccuracy)
                                  .SetInterval(15000)
                                  .SetFastestInterval(5000);

            _fusedLocationClient.RequestLocationUpdates(locationRequest, this, Looper.MainLooper);
        }
示例#9
0
 private void UpdateLocation()
 {
     BuildLocationRequest();
     fusedLocationProviderClient = LocationServices.GetFusedLocationProviderClient(this);
     if (ActivityCompat.CheckSelfPermission(this, Manifest.Permission.AccessLocationExtraCommands) != Android.Content.PM.Permission.Granted)
     {
         return;
     }
     fusedLocationProviderClient.RequestLocationUpdates(locationRequest, GetPendingIntent());
 }
示例#10
0
        private void StartTripButton_Click(object sender, EventArgs e)
        {
            if (!tripStarted)
            {
                Android.Support.V7.App.AlertDialog.Builder alert = new Android.Support.V7.App.AlertDialog.Builder(this);
                alert.SetTitle("Start Trip");
                alert.SetMessage("Are you sure");
                alert.SetPositiveButton("Start", (thisalert, args) =>
                {
                    locationProviderClient.RequestLocationUpdates(mLocationRequest, mLocationCallback, null);
                    tripStarted          = true;
                    startTripButton.Text = "Stop Trip";
                });

                alert.SetNegativeButton("Cancel", (thisalert, args) =>
                {
                    alert.Dispose();
                });

                alert.Show();
            }
            else
            {
                Android.Support.V7.App.AlertDialog.Builder alert = new Android.Support.V7.App.AlertDialog.Builder(this);
                alert.SetTitle("Stop Trip");
                alert.SetMessage("Are you sure");
                alert.SetPositiveButton("Stop", (thisalert, args) =>
                {
                    locationProviderClient.RequestLocationUpdates(mLocationRequest, mLocationCallback, null);
                    tripStarted          = false;
                    startTripButton.Text = "Start Trip";
                    Resetapp();
                });

                alert.SetNegativeButton("Cancel", (thisalert, args) =>
                {
                    alert.Dispose();
                });

                alert.Show();
            }
        }
示例#11
0
        public void UpdateLocation()
        {
            BuildLocationRequest();

            providerClient = LocationServices.GetFusedLocationProviderClient(context);
            if (Android.Support.V4.App.ActivityCompat.CheckSelfPermission(context, Manifest.Permission.AccessFineLocation) != Android.Content.PM.Permission.Granted)
            {
                return;
            }
            providerClient.RequestLocationUpdates(locationRequest, GetPendingIntent());
        }
示例#12
0
 private void UpdateLocation()
 {
     LocationReqvest();
     FusedLocationProviderClient = LocationServices.GetFusedLocationProviderClient(MainActivity);
     if (ActivityCompat.CheckSelfPermission(MainActivity.GetInstance(), Manifest.Permission.AccessFineLocation) != Android.Content.PM.Permission.Granted)
     {
         return;
     }
     gefenceModel.PendingIntent = GetPendingIntent();
     FusedLocationProviderClient.RequestLocationUpdates(locationRequest, gefenceModel.PendingIntent);
 }
 /**
  * Makes a request for location updates. Note that in this sample we merely log the
  * {@link SecurityException}.
  */
 public void RequestLocationUpdates()
 {
     Log.Info(Tag, "Requesting location updates");
     Utils.SetRequestingLocationUpdates(this, true);
     StartService(new Intent(ApplicationContext, typeof(LocationUpdatesService)));
     try {
         FusedLocationClient.RequestLocationUpdates(LocationRequest, LocationCallback, Looper.MyLooper());
     } catch (SecurityException unlikely) {
         Utils.SetRequestingLocationUpdates(this, false);
         Log.Error(Tag, "Lost location permission. Could not request updates. " + unlikely);
     }
 }
示例#14
0
        protected override void OnResume()
        {
            base.OnResume();
            var UserInfoo = DataBase.MEMBER_DATA_GETIR();

            if (UserInfoo.Count > 0)
            {
                if (FusedLocationProviderClient1 != null)
                {
                    FusedLocationProviderClient1.RequestLocationUpdates(LocationRequest1, LocationCallback1, Looper.MyLooper());
                }
            }
        }
示例#15
0
 /**
  * Handles the Request Updates button and requests start of location updates.
  */
 public void RequestLocationUpdates(View view)
 {
     try
     {
         Log.Info(Tag, "Starting location updates");
         Utils.SetRequestingLocationUpdates(this, true);
         mFusedLocationClient.RequestLocationUpdates(mLocationRequest, GetPendingIntent());
     }
     catch (SecurityException e)
     {
         Utils.SetRequestingLocationUpdates(this, false);
         e.PrintStackTrace();
     }
 }
 private async System.Threading.Tasks.Task UpdateLocationAsync(bool turnOn)
 {
     BuildLocationRequest();
     fusedLocationProviderClient = LocationServices.GetFusedLocationProviderClient(this);
     if (await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Location) != PermissionStatus.Granted)
     {
         return;
     }
     if (turnOn)
     {
         fusedLocationProviderClient.RequestLocationUpdates(locationRequest, GetPendingIntent());
     }
     else
     {
         fusedLocationProviderClient.RemoveLocationUpdates(GetPendingIntent());
     }
 }
        public void GetLocation()
        {
            LocationRequest locationRequest = new LocationRequest();

            locationRequest.SetInterval(1000).SetPriority(LocationRequest.PriorityHighAccuracy);

            _locationCallback = new DelegateLocationCallback(locationResult =>
            {
                if (locationResult != null && locationResult.HWLocationList.Count > 0)
                {
                    var location = locationResult.HWLocationList[0];
                    MoveToUserLocation(new LatLng(location.Latitude, location.Longitude));
                    _fusedLocationProviderClient.RemoveLocationUpdates(_locationCallback);
                }
            });

            _fusedLocationProviderClient.RequestLocationUpdates(locationRequest, _locationCallback, MainLooper);
        }
示例#18
0
        private void UpdateLocation()
        {
            try
            {
                BuildLocationRequest();

                fusedLocationProviderClient = LocationServices.GetFusedLocationProviderClient(this);
                if (ActivityCompat.CheckSelfPermission(this, Manifest.Permission.AccessFineLocation) != Android.Content.PM.Permission.Granted)
                {
                    return;
                }

                fusedLocationProviderClient.RequestLocationUpdates(locationRequest, GetPendingIntent());
            }
            catch (Exception ex)
            {
                Toast.MakeText(this, GetString(Resource.String.somthing_wrong), ToastLength.Short).Show();
            }
        }
示例#19
0
        public override void OnCreate()
        {
            base.OnCreate();

            if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
            {
                var notificationManager = (NotificationManager)GetSystemService(Context.NotificationService);

                var notifyChannel = new NotificationChannel(
                    NOTIFY_CHANEL_ID,
                    "FriendLoc",
                    Android.App.NotificationImportance.Max);
                notificationManager.CreateNotificationChannel(notifyChannel);

                Notification notification = new NotificationCompat.Builder(this, NOTIFY_CHANEL_ID)
                                            .SetContentTitle("")
                                            .SetPriority(NotificationCompat.PriorityMax)
                                            .SetContentText("Your location is updating on background").Build();

                StartForeground(1, notification);
            }

            LocationRequest locationRequest = LocationRequest.Create();

            locationRequest.SetInterval(10000);
            locationRequest.SetFastestInterval(5000);
            locationRequest.SetPriority(LocationRequest.PriorityHighAccuracy);

            _fusedLocationClient = LocationServices.GetFusedLocationProviderClient(this);

            _callback = new CusLocationCallback((location) => {
                ServiceInstances.TripRepository.AddLocation(_tripid, new Common.Models.TripLocation()
                {
                    Latitude  = location.Latitude,
                    Longitude = location.Longitude,
                    TripId    = _tripid,
                    UserId    = _userId
                });
            });

            _fusedLocationClient.RequestLocationUpdates(locationRequest, _callback, Looper.MainLooper);
        }
示例#20
0
 void StartLocationUpdates()
 {
     locationProviderClient.RequestLocationUpdates(mLocationRequest, mLocationCallback, null);
 }