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(); }
/// <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()); } }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.main); var toolbar = FindViewById <Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar); if (toolbar != null) { SetSupportActionBar(toolbar); SupportActionBar.SetDisplayHomeAsUpEnabled(false); SupportActionBar.SetHomeButtonEnabled(false); } startButton = FindViewById <Button>(Resource.Id.start_updates_button); startButton.Click += async(sender, args) => await StartLocationUpdatesAsync(); stopButton = FindViewById <Button>(Resource.Id.stop_updates_button); stopButton.Click += (sender, args) => StopLocationUpdates(); latitudeTextView = FindViewById <TextView>(Resource.Id.latitude_text); longitudeTextView = FindViewById <TextView>(Resource.Id.longitude_text); timeTextView = FindViewById <TextView>(Resource.Id.last_update_time_text); fusedLocationClient = LocationServices.GetFusedLocationProviderClient(this); settingsClient = LocationServices.GetSettingsClient(this); if (bundle != null) { var keys = bundle.KeySet(); if (keys.Contains(KeyRequesting)) { requestingUpdates = bundle.GetBoolean(KeyRequesting); } if (keys.Contains(KeyLocation)) { currentLocation = bundle.GetParcelable(KeyLocation) as Location; } if (keys.Contains(KeyLastUpdated)) { lastUpdateTime = bundle.GetString(KeyLastUpdated); } } locationCallback = new MyLocationCallback(); //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 locationRequest = new LocationRequest() .SetInterval(UpdateInterval) .SetFastestInterval(FastestUpdateInterval) .SetPriority(LocationRequest.PriorityHighAccuracy); locationSettingsRequest = new LocationSettingsRequest.Builder().AddLocationRequest(locationRequest).Build(); UpdateUI(); }
private void InitializeGoogleAPI() { int queryResult = GoogleApiAvailability.Instance.IsGooglePlayServicesAvailable(Android.App.Application.Context); if (queryResult == ConnectionResult.Success) { string message = string.Format("{0} - {1}", CrossGeofence.Id, "Google Play services is available."); System.Diagnostics.Debug.WriteLine(message); if (mGeofenceClient == null) { mGeofenceClient = LocationServices.GetGeofencingClient(Android.App.Application.Context); } if (mFusedLocationClient == null) { var locationRequest = GetLocationRequest(); mFusedLocationClient = LocationServices.GetFusedLocationProviderClient(Android.App.Application.Context); mFusedLocationClient.RequestLocationUpdatesAsync(locationRequest, new FusedLocationCallback(this)); } //if (!mGoogleApiClient.IsConnected) //{ // mGoogleApiClient.Connect(); //} } else { string message = string.Format("{0} - {1}", CrossGeofence.Id, "Google Play services is unavailable."); System.Diagnostics.Debug.WriteLine(message); CrossGeofence.GeofenceListener.OnError(message); } }
protected override async void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.Main); fusedLocationProviderClient = LocationServices.GetFusedLocationProviderClient(this); rootLayout = FindViewById(Resource.Layout.Main); checkPermission(); if (IsGooglePlayServicesInstalled()) { var lastLocation = await GetLastLocationFromDevice(); double?longitude = lastLocation?.longitude; double?latitude = lastLocation?.latitude; WeatherService weather = new WeatherService(); TextView weatherResponseText = FindViewById <TextView>(Resource.Id.textView1); weatherResponseText.Text = weather.GetWeather(latitude.ToString(), longitude.ToString()); } 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(); } // Create your application here }
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()); }
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()); }
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); }
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); } }
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(); }
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(); } }
/// <inheritdoc /> public override void OnCreate() { _fusedLocationClient = LocationServices.GetFusedLocationProviderClient(this); _locationCallback = new LocationCallback(); _locationCallback.LocationResult += (sender, args) => OnNewLocation(args.Result.LastLocation); CreateLocationRequest(); GetLastLocation(); var handlerThread = new HandlerThread(Tag); handlerThread.Start(); _serviceHandler = new Handler(handlerThread.Looper); _notificationManager = (NotificationManager)GetSystemService(NotificationService); // Android O requires a Notification Channel. if (Build.VERSION.SdkInt >= BuildVersionCodes.O) { var name = GetString(Resource.String.app_name); // Create the channel for the notification var mChannel = new NotificationChannel(ChannelId, name, NotificationImportance.Low); // Set the Notification Channel for the Notification Manager. _notificationManager.CreateNotificationChannel(mChannel); } }
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(); }
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); } }
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(); } }
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); }
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 }
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) { } }
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); }
// 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); }
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(); }
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 StopLocationRequest() { if (activity != null) { LocationServices.GetFusedLocationProviderClient(activity).RemoveLocationUpdates(mCallback); } }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); Xamarin.Essentials.Platform.Init(this, savedInstanceState); // Set our view from the "main" layout resource SetContentView(P6Test.Resource.Layout.TestLocation); Plugin.CurrentActivity.CrossCurrentActivity.Current.Init(this, bundle); Instance = this; fusedLocationProviderClient = LocationServices.GetFusedLocationProviderClient(this); Dexter.WithActivity(this) .WithPermission(Manifest.Permission.AccessFineLocation) .WithListener(this) .Check(); CreateNotificationChannel(); Intent StartServiceIntent = new Intent(this, typeof(ForegroundMethod)); StartServiceIntent.SetAction("Service.action.START_SERVICE"); StartForegroundService(StartServiceIntent); /*FindViewById<Button>(P6Test.Resource.Id.LocationBtn).Click += (o, e) => * { * getLocation(); * }; * * FindViewById<Button>(P6Test.Resource.Id.resetButton).Click += (o, e) => * { * i = 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); } }
public LocationService(Activity mainActivity) { this.mainActivity = mainActivity; locationProvider = LocationServices.GetFusedLocationProviderClient(Application.Context); locationCallback = new EdisonLocationCallback(); locationCallback.LocationUpdated += OnLocationUpdated; }
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(); }
/* * Start receiving location updates */ void ILocationManager.StartLocationUpdates() { client = LocationServices.GetFusedLocationProviderClient(CrossCurrentActivity.Current.Activity); LocationRequest request = new LocationRequest().SetPriority(LocationRequest.PriorityHighAccuracy).SetInterval(1000 * 5).SetFastestInterval(1000 * 2); locationCallback = new ClientLocationCallback(CrossCurrentActivity.Current.Activity); client.RequestLocationUpdatesAsync(request, locationCallback); }
public GpsManagerImpl(AndroidContext context) { this.context = context; this.client = LocationServices.GetFusedLocationProviderClient(this.context.AppContext); //if (this.IsListening) // this.StartListenerInternal(); // fire and forget }
protected override async void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.CustomMap); _toolbar = FindViewById <Toolbar>(Resource.Id.tv_cm_toolbar); SetSupportActionBar(_toolbar); SupportActionBar.SetDisplayHomeAsUpEnabled(true); SupportActionBar.SetHomeButtonEnabled(true); _setPlaceButton = FindViewById <Button>(Resource.Id.btn_cm_setCoordinates); PlaceAutocompleteFragment autocompleteFragment = (PlaceAutocompleteFragment)FragmentManager.FindFragmentById(Resource.Id.place_autocomplete_fragment); var content = Intent.GetStringExtra("place"); _isEditable = Intent.GetBooleanExtra("isEditable", false); if (!_isEditable) { autocompleteFragment.View.Visibility = ViewStates.Gone; _setPlaceButton.Visibility = ViewStates.Gone; } else { autocompleteFragment.SetOnPlaceSelectedListener(this); autocompleteFragment.SetBoundsBias(new LatLngBounds( new LatLng(4.5931, -74.1552), new LatLng(4.6559, -74.0837))); _setPlaceButton.Click += SetPlaceButton_Click; } if (!string.IsNullOrWhiteSpace(content)) { _markerPosition = JsonConvert.DeserializeObject <Coordinates>(content); } _fusedLocationProviderClient = LocationServices.GetFusedLocationProviderClient(this); _mapFragment = FragmentManager.FindFragmentByTag("map") as MapFragment; if (_mapFragment == null) { Location location = await _fusedLocationProviderClient.GetLastLocationAsync(); var myPosition = new LatLng(location.Latitude, location.Longitude);// (20.5, 20.5); GoogleMapOptions mapOptions = new GoogleMapOptions() .InvokeMapType(GoogleMap.MapTypeNormal) .InvokeZoomControlsEnabled(true) .InvokeMapToolbarEnabled(true) .InvokeCamera(new CameraPosition(myPosition, 10, 0, 0)) .InvokeCompassEnabled(true); FragmentTransaction fragTx = FragmentManager.BeginTransaction(); _mapFragment = MapFragment.NewInstance(mapOptions); fragTx.Add(Resource.Id.map, _mapFragment, "map"); fragTx.Commit(); } _mapFragment.GetMapAsync(this); }