예제 #1
0
        private void CheckLocationSettings()
        {
            LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
                                                      .AddLocationRequest(mLocationRequest);
            builder.SetAlwaysShow(true);
            var task = LocationServices.GetSettingsClient(Activity).CheckLocationSettings(builder.Build());

            task.AddOnSuccessListener(new OnSuccessListener(t =>
            {
                mLocationCallback.MyLocation += MLocationCallback_MyLocation;
            })).AddOnFailureListener(new OnFailureListener(e =>
            {
                int statusCode = ((ApiException)e).StatusCode;
                switch (statusCode)
                {
                case CommonStatusCodes.ResolutionRequired:
                    try
                    {
                        ResolvableApiException resolvable = (ResolvableApiException)e;
                        StartIntentSenderForResult(resolvable.Resolution.IntentSender, RequestCode, null, 0, 0, 0, null);
                    }
                    catch (SendIntentException)
                    {
                    }
                    catch (ClassCastException)
                    {
                    }
                    break;

                case LocationSettingsStatusCodes.SettingsChangeUnavailable:

                    break;
                }
            }));
        }
예제 #2
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);
     }
 }
예제 #3
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);
        }
예제 #4
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);


            Window.RequestFeature(WindowFeatures.NoTitle);
            SetContentView(Resource.Layout.activity_main);

            if (IsGooglePlayServicesInstalled())
            {
                _fusedLocationProviderClient = LocationServices.GetFusedLocationProviderClient(this);
                _locationTextView            = FindViewById <TextView>(Resource.Id.textViewCoordinates);

                _locationRequest = new LocationRequest()
                                   .SetPriority(LocationRequest.PriorityHighAccuracy)
                                   .SetInterval(5 * 1000)
                                   .SetFastestInterval(5 * 1000);

                ActivityCompat.RequestPermissions(this, new[] { Manifest.Permission.AccessFineLocation }, RC_LOCATION_UPDATES_PERMISSION_CHECK);
            }

            InitializeDataSetFetchers();

            InitializeSearchStrategies();

            InitializeSearchAlgorithms();

            SetupDataSetSpinner();
            SetupSearchMethodSpinner();
            SetupSearchEditText();
        }
예제 #5
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            if (bundle != null)
            {
                isRequestingLocationUpdates = bundle.KeySet().Contains(KEY_REQUESTING_LOCATION_UPDATES) &&
                                              bundle.GetBoolean(KEY_REQUESTING_LOCATION_UPDATES);
            }
            else
            {
                isRequestingLocationUpdates = false;
            }

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);
            isGooglePlayServicesInstalled = IsGooglePlayServicesInstalled();
            rootLayout = FindViewById(Resource.Id.root_layout);

            // UI to display last location
            getLastLocationButton = FindViewById <Button>(Resource.Id.get_last_location_button);
            latitude  = FindViewById <TextView>(Resource.Id.latitude);
            longitude = FindViewById <TextView>(Resource.Id.longitude);
            provider  = FindViewById <TextView>(Resource.Id.provider);

            // UI to display location updates
            requestLocationUpdatesButton = FindViewById <Button>(Resource.Id.request_location_updates_button);
            latitude2  = FindViewById <TextView>(Resource.Id.latitude2);
            longitude2 = FindViewById <TextView>(Resource.Id.longitude2);
            provider2  = FindViewById <TextView>(Resource.Id.provider2);

            //addressText = FindViewById<TextView>(Resource.Id.address_text);
            //locationText = FindViewById<TextView>(Resource.Id.location_text);
            macAddressText   = FindViewById <TextView>(Resource.Id.macaddress);
            batteryLevelText = FindViewById <TextView>(Resource.Id.batterylevel);

            //batteryLevelText = FindViewById<TextView>(Resource.Id.batterylevel_text);
            //FindViewById<TextView>(Resource.Id.get_address_button).Click += AddressButton_OnClick;


            if (isGooglePlayServicesInstalled)
            {
                locationRequest = new LocationRequest()
                                  .SetPriority(LocationRequest.PriorityHighAccuracy)
                                  .SetInterval(FIVE_MINUTES)
                                  .SetFastestInterval(TWO_MINUTES);
                locationCallback = new FusedLocationProviderCallback(this);

                fusedLocationProviderClient         = LocationServices.GetFusedLocationProviderClient(this);
                getLastLocationButton.Click        += GetLastLocationButtonOnClick;
                requestLocationUpdatesButton.Click += RequestLocationUpdatesButtonOnClick;
            }
            else
            {
                // If there is no Google Play Services installed, then this sample won't run.
                Snackbar.Make(rootLayout, Resource.String.missing_googleplayservices_terminating, Snackbar.LengthIndefinite)
                .SetAction(Resource.String.ok, delegate { FinishAndRemoveTask(); })
                .Show();
            }
        }
예제 #6
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.main_activity);
            var toolbar = FindViewById <Toolbar>(Resource.Id.toolbar);

            SetSupportActionBar(toolbar);

            mStartUpdatesButton     = FindViewById <Button>(Resource.Id.start_updates_button);
            mStopUpdatesButton      = FindViewById <Button>(Resource.Id.stop_updates_button);
            mLatitudeTextView       = FindViewById <TextView>(Resource.Id.latitude_text);
            mLongitudeTextView      = FindViewById <TextView>(Resource.Id.longitude_text);
            mLastUpdateTimeTextView = FindViewById <TextView>(Resource.Id.last_update_time_text);

            mStartUpdatesButton.Click += StartUpdatesButtonHandler;
            mStopUpdatesButton.Click  += StopUpdatesButtonHandler;

            mLatitudeLabel       = GetString(Resource.String.latitude_label);
            mLongitudeLabel      = GetString(Resource.String.longitude_label);
            mLastUpdateTimeLabel = GetString(Resource.String.last_update_time_label);

            mRequestingLocationUpdates = false;
            mLastUpdateTime            = string.Empty;

            UpdateValuesFromBundle(savedInstanceState);

            mFusedLocationClient = LocationServices.GetFusedLocationProviderClient(this);
            mSettingsClient      = LocationServices.GetSettingsClient(this);

            CreateLocationCallback();
            CreateLocationRequest();
            BuildLocationSettingsRequest();
        }
예제 #7
0
        void KonumSor()
        {
            var UserInfoo = DataBase.MEMBER_DATA_GETIR();

            if (UserInfoo.Count > 0)
            {
                if (ContextCompat.CheckSelfPermission(this, Android.Manifest.Permission.AccessFineLocation) == Permission.Granted)
                {
                    BuildLocationRequest();
                    LocationCallBack();
                    FusedLocationProviderClient1 = LocationServices.GetFusedLocationProviderClient(this);
                    if (KonumKontrol())
                    {
                        BekletVeUygula();
                    }
                }
                else
                {
                    RequestPermissions(new String[] { Android.Manifest.Permission.AccessFineLocation }, 1);
                }
            }
            else
            {
                StartActivity(typeof(LoginBaseActivity));
                this.Finish();
            }
        }
예제 #8
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            if (bundle != null)
            {
                isRequestingLocationUpdates = bundle.KeySet().Contains(KEY_REQUESTING_LOCATION_UPDATES) &&
                                              bundle.GetBoolean(KEY_REQUESTING_LOCATION_UPDATES);
            }
            else
            {
                isRequestingLocationUpdates = false;
            }

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);
            isGooglePlayServicesInstalled = IsGooglePlayServicesInstalled();
            rootLayout = FindViewById(Resource.Id.root_layout);

            // UI to display last location
            getLastLocationButton = FindViewById <Button>(Resource.Id.get_last_location_button);
            latitude  = FindViewById <TextView>(Resource.Id.latitude);
            longitude = FindViewById <TextView>(Resource.Id.longitude);
            speed     = FindViewById <TextView>(Resource.Id.speed);
            provider  = FindViewById <TextView>(Resource.Id.provider);

            // UI to display location updates
            requestLocationUpdatesButton = FindViewById <Button>(Resource.Id.request_location_updates_button);
            latitude2        = FindViewById <TextView>(Resource.Id.latitude2);
            longitude2       = FindViewById <TextView>(Resource.Id.longitude2);
            speed2           = FindViewById <TextView>(Resource.Id.speed2);
            provider2        = FindViewById <TextView>(Resource.Id.provider2);
            fileLogger       = new FileLogger();
            _locationFetcher = new Timer();

            if (isGooglePlayServicesInstalled)
            {
                locationRequest = new LocationRequest()
                                  .SetPriority(LocationRequest.PriorityHighAccuracy)
                                  .SetInterval(1000)
                                  .SetFastestInterval(1000);
                locationCallback = new FusedLocationProviderCallback(this);

                fusedLocationProviderClient         = LocationServices.GetFusedLocationProviderClient(this);
                getLastLocationButton.Click        += GetLastLocationButtonOnClick;
                requestLocationUpdatesButton.Click += RequestLocationUpdatesButtonOnClick;
            }
            else
            {
                // If there is no Google Play Services installed, then this sample won't run.
                Snackbar.Make(rootLayout, Resource.String.missing_googleplayservices_terminating, Snackbar.LengthIndefinite)
                .SetAction(Resource.String.ok, delegate { FinishAndRemoveTask(); })
                .Show();
            }
            //_locationFetcher.Elapsed += new ElapsedEventHandler(Timer_Elapsed);
            //_locationFetcher.Interval = 1000;
            //_locationFetcher.Start();

            Start();
        }
예제 #9
0
        private void InitLocationRequest()
        {
            try
            {
                locationRequest = new LocationRequest()
                                  .SetPriority(LocationRequest.PriorityHighAccuracy)
                                  .SetInterval(6 * 1000 * 2)
                                  .SetFastestInterval(6 * 1000);

                locationCallback            = new FusedLocationProviderCallback((MainActivity)CrossCurrentActivity.Current.Activity);
                fusedLocationProviderClient = LocationServices.GetFusedLocationProviderClient(CrossCurrentActivity.Current.Activity);

                /*Criteria locationCriteria = new Criteria();
                 * //locationCriteria.Accuracy = Accuracy.High;
                 * locationCriteria.PowerRequirement = Power.High;
                 *
                 * var locationProvider = locationManager.GetBestProvider(locationCriteria, true);
                 *
                 * var intent = new Intent(CrossCurrentActivity.Current.Activity, typeof(MainActivity));
                 * var resultPendingIntent = PendingIntent.GetActivity(Forms.Context, 0, intent, PendingIntentFlags.OneShot);
                 *
                 * locationManager.RequestLocationUpdates(locationProvider, 2000, 1, resultPendingIntent);*/
            }
            catch (Exception ex)
            {
                Log.Error("GPS EXCEPTION", ex.StackTrace);
            }
        }
 public LocationController(LocationServices locationServices, BasicInfoServices basicInfoServices
                           , ILogger <LocationController> logger)
     : base(logger)
 {
     _locationServices  = locationServices;
     _basicInfoServices = basicInfoServices;
 }
예제 #11
0
 /// <summary>
 /// 登録後のリスナーを指定してクラスをインスタンス化します。
 /// </summary>
 /// <param name="context"></param>
 /// <param name="completeListener"></param>
 public RegisterGeofences(Context context, IGeofenceRegisterCompleteListener completeListener)
 {
     _context          = context;
     _geofencingClient = LocationServices.GetGeofencingClient(context);
     CompleteListener  = completeListener;
     PopulateGeofenceList();
 }
예제 #12
0
        private async void SetGeofence()
        {
            var locationClient = LocationServices.GetFusedLocationProviderClient(this);


            var geofencingClient = LocationServices.GetGeofencingClient(this);

            var lastLocation = await locationClient.GetLastLocationAsync();

            var geoFence = new GeofenceBuilder()
                           .SetRequestId("fence")
                           .SetCircularRegion(lastLocation.Latitude, lastLocation.Longitude, 100)
                           .SetTransitionTypes(Geofence.GeofenceTransitionExit | Geofence.GeofenceTransitionEnter)
                           .SetExpirationDuration(Geofence.NeverExpire)
                           .Build();

            var geofenceRequest = new GeofencingRequest.Builder()
                                  .AddGeofence(geoFence)
                                  .Build();

            var geoIntent        = new Intent(ApplicationContext, typeof(GeofenceTransitionsService));
            var pendingGeoIntent = PendingIntent.GetService(this, 0, geoIntent, PendingIntentFlags.UpdateCurrent);

            geofencingClient.AddGeofences(geofenceRequest, pendingGeoIntent);
        }
예제 #13
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.activity_home);

            StaticMenu.id_page = 1;

            home_container = FindViewById <RelativeLayout>(Resource.Id.home_container);
            s_user         = FindViewById <TextView>(Resource.Id.s_user);

            s_user.Text = StaticUser.FirstName + " " + StaticUser.LastName;

            MapFragment mapFragment = (MapFragment)FragmentManager.FindFragmentById(Resource.Id.fragmentMap);

            mapFragment.GetMapAsync(this);

            BuildLocationRequest();
            BuildLocationCallBack();

            fusedLocationProviderClient = LocationServices.GetFusedLocationProviderClient(this);

            //ResetUser();
            fusedLocationProviderClient.RequestLocationUpdates(locationRequest,
                                                               locationCallback, Looper.MyLooper());

            //Task.Delay(1000).ContinueWith(t =>
            //{
            //	OnMapReady(_googleMap);
            //}, TaskScheduler.FromCurrentSynchronizationContext());
        }
예제 #14
0
        /// <summary>
        /// Loads all of the needed elements
        /// </summary>
        /// <param name="savedInstanceState"></param>
        protected override void OnCreate(Bundle savedInstanceState)
        {
            try
            {
                base.OnCreate(savedInstanceState);

                Forms.Init(this, savedInstanceState);
                Xamarin.Essentials.Platform.Init(this, savedInstanceState);

                SetContentView(Resource.Layout.activity_main);

                finalOrder = new FinalOrder();

                fusedLocationProviderClient = LocationServices.GetFusedLocationProviderClient(this);
                var location = fusedLocationProviderClient.GetLastLocationAsync();

                MapFragment mapFragment = (MapFragment)FragmentManager.FindFragmentById(Resource.Id.map);

                mapFragment.GetMapAsync(this);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }
예제 #15
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.activity_task_list);

            s_order         = FindViewById <EditText>(Resource.Id.s_order);
            s_task          = FindViewById <EditText>(Resource.Id.s_task);
            btn_abort_order = FindViewById <Button>(Resource.Id.btn_abort_order);
            btn_performed   = FindViewById <Button>(Resource.Id.btn_performed);

            MapFragment mapFragment = (MapFragment)FragmentManager.FindFragmentById(Resource.Id.fragmentMap);

            mapFragment.GetMapAsync(this);

            s_order.Focusable     = false;
            s_order.LongClickable = false;
            s_task.Focusable      = false;
            s_task.LongClickable  = false;

            BuildLocationRequest();
            BuildLocationCallBack();

            fusedLocationProviderClient = LocationServices.GetFusedLocationProviderClient(this);

            //ResetUser();
            fusedLocationProviderClient.RequestLocationUpdates(locationRequest,
                                                               locationCallback, Looper.MyLooper());
        }
        public override void OnCreate()
        {
            mGeofenceList = new List <IGeofence>();
            Dictionary <string, double> nord = new Dictionary <string, double>()
            {
                { "lat", 39.716864 },
                { "lng", -104.955342 }
            };

            Dictionary <string, double> test = new Dictionary <string, double>()
            {
                { "lat", 39.716 },
                { "lng", -104.955 }
            };

            GeofencingClient geofencingClient = LocationServices.GetGeofencingClient(this);

            mGeofenceList.Add(new GeofenceBuilder()
                              .SetRequestId("nord")
                              .SetCircularRegion(nord["lat"], nord["lng"], 3f)
                              .SetExpirationDuration(Geofence.NeverExpire)
                              .SetTransitionTypes(Geofence.GeofenceTransitionEnter | Geofence.GeofenceTransitionExit)
                              .Build());

            geofencingClient.AddGeofences(GetGeofencingRequest(), GetGeofencePendingIntent());
            Console.WriteLine("WTF WTF WTF WTF");
            Log.Debug("THIS", "WTF Created!");
        }
예제 #17
0
 public void StopLocationRequest()
 {
     if (activity != null)
     {
         LocationServices.GetFusedLocationProviderClient(activity).RemoveLocationUpdates(mCallback);
     }
 }
예제 #18
0
        protected override void OnCreate(Bundle bundle)
        {
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource   = Resource.Layout.Toolbar;

            UserDialogs.Init(this);

            FirebaseApp.InitializeApp(this);
            firebaseAnalytics = FirebaseAnalytics.GetInstance(this);

            var playAvailable = IsPlayServicesAvailable();

            if (playAvailable)
            {
                new GetRemoteConfig();
                Intent locIntent = new Intent(this, typeof(SaleLocationService));
                StartService(locIntent);
                fusedLocationProviderClient = LocationServices.GetFusedLocationProviderClient(this);
                FusedLocationProviderCallback callback = new FusedLocationProviderCallback(this);
                fusedLocationProviderClient.RequestLocationUpdatesAsync(callback.LocationRequest, callback);
            }

            base.OnCreate(bundle);

            global::Xamarin.Forms.Forms.Init(this, bundle);
            global::Xamarin.FormsMaps.Init(this, bundle);
            LoadApplication(new App());
#if DEBUG
            MocksLocation();
#endif
        }
예제 #19
0
 public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Permission[] grantResults)
 {
     base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
     if (permissions.Length == 1 &&
         permissions[0] == Android.Manifest.Permission.AccessFineLocation && grantResults[0] == Permission.Granted)
     {
         if (ContextCompat.CheckSelfPermission(this, Android.Manifest.Permission.AccessFineLocation) != Permission.Granted && ContextCompat.CheckSelfPermission(this, Android.Manifest.Permission.AccessFineLocation) != Permission.Granted)
         {
             return;
         }
         BuildLocationRequest();
         LocationCallBack();
         FusedLocationProviderClient1 = LocationServices.GetFusedLocationProviderClient(this);
         if (KonumKontrol())
         {
             BekletVeUygula();
         }
     }
     else
     {
         if (KonumKontrol())
         {
             BekletVeUygula();
         }
     }
 }
        public void CheckLocationSetting()
        {
            TestTip.Inst.ShowText("RequestLocationUpdatesWithCallback start");
            this.requestType             = CALLBACK;
            mFusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(new Context());
            mSettingsClient  = LocationServices.getSettingsClient(new Context());
            mLocationRequest = new LocationRequest();
            mLocationRequest.setInterval(5000);
            mLocationRequest.setPriority(102);
            // get LocationSettingsRequest
            LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder();
            builder.addLocationRequest(mLocationRequest);
            LocationSettingsRequest locationSettingsRequest = builder.build();

            Task task = mSettingsClient.checkLocationSettings(locationSettingsRequest);

            task.addOnSuccessListener(new HmsSuccessListener <LocationSettingsResponse>((LocationSettingsResponse setting) =>
            {
                var status = setting.getLocationSettingsStates();
                TestTip.Inst.ShowText($"isBlePresent :{status.isBlePresent()}");
                TestTip.Inst.ShowText($"isBleUsable :{status.isBleUsable()}");
                TestTip.Inst.ShowText($"isGpsPresent :{status.isGpsPresent()}");
                TestTip.Inst.ShowText($"isGpsUsable :{status.isGpsUsable()}");
                TestTip.Inst.ShowText($"isLocationPresent :{status.isLocationPresent()}");
                TestTip.Inst.ShowText($"isLocationUsable :{status.isLocationUsable()}");
                TestTip.Inst.ShowText($"isNetworkLocationPresent :{status.isNetworkLocationPresent()}");
                TestTip.Inst.ShowText($"isNetworkLocationUsable :{status.isNetworkLocationUsable()}");
            })).addOnFailureListener(new HmsFailureListener((Exception e) => SetSettingsFailuer(e)));
        }
예제 #21
0
        // Lighthouse

        private async void StartLighthouse()
        {
            System.Diagnostics.Debug.WriteLine("StartLighthouse");

            // Initialize Estimote (TODO: Remove values when distributing)
            EstimoteSdk.Common.Config.Estimote.EnableDebugLogging(true);
            EstimoteSdk.Common.Config.Estimote.Initialize(Application.Context, LHPEEstimoteId, LHPEEstimoteKey);

            // Initialize GPS Location
            if (IsPlayServicesAvailable())
            {
                locationRequest = new LocationRequest()
                                  .SetPriority(LocationRequest.PriorityBalancedPowerAccuracy)
                                  .SetInterval(1000)
                                  .SetFastestInterval(locationFrequencySeconds * 1000);
                locationCallback = new FusedLocationProviderCallback((MainActivity)CrossCurrentActivity.Current.Activity);

                fusedLocationProviderClient = LocationServices.GetFusedLocationProviderClient(this);
            }

            // Initialize lhpe
            await Lighthouse.Start(LHPEEnvironment, LHPEAppId, LHPEAppKey);

            // Stop Loading Activity, Start Main Activity
            var intent = new Intent(this, typeof(LHPEXamarinSample.Droid.MainActivity));

            StartActivity(intent);
        }
        public void RequestLocationUpdates(int priority, int requestType)
        {
            TestTip.Inst.ShowText("RequestLocationUpdatesWithCallback start");
            this.requestType             = requestType;
            mFusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(new Context());
            mSettingsClient  = LocationServices.getSettingsClient(new Context());
            mLocationRequest = new LocationRequest();
            mLocationRequest.setInterval(5000);
            mLocationRequest.setPriority(priority);
            // get LocationSettingsRequest
            LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder();
            builder.addLocationRequest(mLocationRequest);
            LocationSettingsRequest locationSettingsRequest = builder.build();

            Task task = mSettingsClient.checkLocationSettings(locationSettingsRequest);

            task.addOnSuccessListener(new LocationSuccessListener((AndroidJavaObject o) =>
            {
                switch (requestType)
                {
                case CALLBACK:
                    SetCallbackSuccess();
                    break;

                case INTENT:
                    SetIntentSuccess();
                    break;

                case LocationHD:
                    SetHDSuccess();
                    break;
                }
            }));
            task.addOnFailureListener(new HmsFailureListener((Exception e) => SetSettingsFailuer(e)));
        }
예제 #23
0
        async Task StartLocationUpdatesAsync()
        {
            // Create a callback that will get the location updates
            if (locationCallback == null)
            {
                locationCallback = new MyLocationCallback();
                locationCallback.LocationUpdated += OnLocationResult;
            }

            // Get the current client
            if (locationClient == null)
            {
                locationClient = LocationServices.GetFusedLocationProviderClient(this);
            }

            try
            {
                //Create request and set intervals:
                //Interval: Desired interval for active location updates, it is inexact and you may not receive upates at all if no location servers are available
                //Fastest: Interval is exact and app will never receive updates faster than this value
                var locationRequest = new LocationRequest()
                                      .SetInterval(10000)
                                      .SetFastestInterval(5000)
                                      .SetPriority(LocationRequest.PriorityHighAccuracy);

                await locationClient.RequestLocationUpdatesAsync(locationRequest, locationCallback);
            }
            catch (Exception)
            {
            }
        }
        public ActionResult NewUser(UserModel user, UserFilterModel filter)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    EmployeeServices.CreateUser(user);
                    return(RedirectToAction("UserListing", filter.GenerateUserAccessRoute()));
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex.ToString());
                ModelState.AddModelError(String.Empty, Constants.ServerError);
            }

            // Invalid - redisplay with errors
            var model = new UserDetailModel()
            {
                Action = "NewUser",
                User   = user,
                Filter = filter,
                Roles  = LookupServices.GetRoleOptions(user.RoleName)
            };

            ViewBag.Locations = LocationServices.GetLocationLookup(true, -1);
            return(View("UserDetail", model));
        }
예제 #25
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.activity_main);

            mRequestUpdatesButton      = FindViewById(Resource.Id.request_updates_button) as Button;
            mRemoveUpdatesButton       = FindViewById(Resource.Id.remove_updates_button) as Button;
            mLocationUpdatesResultView = FindViewById(Resource.Id.location_updates_result) as TextView;

            mRequestUpdatesButton.Click += (sender, e) => {
                RequestLocationUpdates(null);
            };

            mRemoveUpdatesButton.Click += (sender, e) => {
                RemoveLocationUpdates(null);
            };

            // Check if the user revoked runtime permissions.
            if (!CheckPermissions())
            {
                RequestPermissions();
            }

            mFusedLocationClient = LocationServices.GetFusedLocationProviderClient(this);
            CreateLocationRequest();
        }
        public ActionResult EditUser(int id, UserFilterModel filter, FormCollection collection)
        {
            var user = EmployeeServices.GetUser(id);

            try
            {
                UpdateModel(user, "User");
                EmployeeServices.UpdateUser(user);

                return(RedirectToAction("UserListing", filter.GenerateUserAccessRoute()));
            }
            catch (Exception ex)
            {
                // Invalid - redisplay with errors
                Logger.Error(ex.ToString());
                ModelState.AddModelError(String.Empty, Constants.ServerError);
                var model = new UserDetailModel()
                {
                    Action = "EditUser",
                    User   = user,
                    Filter = filter,
                    Roles  = LookupServices.GetRoleOptions(user.RoleName)
                };

                ViewBag.Locations = LocationServices.GetLocationLookup(true, model.User.LocationId);
                return(View("UserDetail", model));
            }
        }
예제 #27
0
 public LocationService(Activity mainActivity)
 {
     this.mainActivity = mainActivity;
     locationProvider  = LocationServices.GetFusedLocationProviderClient(Application.Context);
     locationCallback  = new EdisonLocationCallback();
     locationCallback.LocationUpdated += OnLocationUpdated;
 }
예제 #28
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);
            }
        }
예제 #29
0
        protected override async void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            var locationClient = LocationServices.GetFusedLocationProviderClient(this);

            var geofencingClient = LocationServices.GetGeofencingClient(this);

            var lastLocation = await locationClient.GetLastLocationAsync();

            var geoFence = new GeofenceBuilder()
                           .SetRequestId("fence")
                           .SetCircularRegion(lastLocation.Latitude, lastLocation.Longitude, 100)
                           .SetTransitionTypes(Geofence.GeofenceTransitionExit | Geofence.GeofenceTransitionEnter)
                           .SetExpirationDuration(Geofence.NeverExpire)
                           .Build();

            var geofenceRequest = new GeofencingRequest.Builder()
                                  .SetInitialTrigger(GeofencingRequest.InitialTriggerEnter)
                                  .AddGeofence(geoFence)
                                  .Build();

            var geoIntent        = new Intent(this, typeof(GeofenceTransitionsService));
            var pendingGeoIntent = PendingIntent.GetService(this, 0, geoIntent, PendingIntentFlags.UpdateCurrent);

            geofencingClient.AddGeofences(geofenceRequest, pendingGeoIntent);
        }
예제 #30
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();
        }
예제 #31
0
        private static Vector Calculate(IRandom random)
        {
            ILocationServices svc = new LocationServices(random);

            var location = new Mock<ILocation>(MockBehavior.Strict);
            location.SetupGet(x => x.Position).Returns(new Position(location.Object, Vector.Zero));

            var result = svc.GetExitPosition(location.Object);
            return result;
        }