protected override void OnCreate(Bundle savedInstanceState)
        {
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource   = Resource.Layout.Toolbar;

            base.OnCreate(savedInstanceState);
            global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
            LoadApplication(new App());

            //Käynnistetään GPS-paikannus
            try
            {
                LocationManager = GetSystemService(
                    "location") as LocationManager;
                string Provider = LocationManager.GpsProvider;

                if (LocationManager.IsProviderEnabled(Provider))
                {
                    LocationManager.RequestLocationUpdates(
                        Provider, 2000, 1, this);
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
        }
        /// <summary>
        /// コンストラクタ
        /// </summary>
        /// <param name="context"></param>
        public LocationTracker(Context context, string provider = LocationManager.GpsProvider)
        {
            locationMan = (LocationManager)context.GetSystemService(Service.LocationService);

            if(locationMan.GetProviders(true).Contains(provider))
            {
                Provider = provider;
            }
            else if (locationMan.IsProviderEnabled(LocationManager.GpsProvider))
            {
                Provider = LocationManager.GpsProvider;
            }
            else if (locationMan.IsProviderEnabled(LocationManager.NetworkProvider))
            {
                Provider = LocationManager.NetworkProvider;
            }
            else
            {
                Criteria crit = new Criteria();
                crit.Accuracy = Accuracy.Fine;
                Provider = locationMan.GetBestProvider(crit, true);
            }

            LastGPSReceived = DateTime.MinValue;
        }
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // use location service directly
            _locMgr = GetSystemService(LocationService) as LocationManager;
        }
Exemple #4
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            AndroidMainActivity = this;

            global::Xamarin.Forms.Forms.Init(this, bundle);
            LoadApplication(new App());

            // käynnistetään GPS-paikannus
            try
            {
                LocationManager = GetSystemService(
                    "location") as LocationManager;
                string Provider = LocationManager.GpsProvider;

                if (LocationManager.IsProviderEnabled(Provider))
                {
                    LocationManager.RequestLocationUpdates(
                        Provider, 2000, 1, this);
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
        }
        protected override void OnCreate (Bundle bundle)
		{
			base.OnCreate (bundle);

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

            // Get our button from the layout resource,
            // and attach an event to it
            nameEditText = FindViewById<EditText>(Resource.Id.firstNameTextField);
            surnameEditText = FindViewById<EditText>(Resource.Id.surNameTextField);

            locM = GetSystemService(Context.LocationService) as LocationManager;
            if (locM.IsProviderEnabled(LocationManager.GpsProvider))
                locM.RequestLocationUpdates(LocationManager.GpsProvider, 2000, 1, this);


            Button notificationButton1 = FindViewById<Button>(Resource.Id.notificationButton1);
            Button notificationButton2 = FindViewById<Button>(Resource.Id.notificationbutton2);
            Button notificationButton3 = FindViewById<Button>(Resource.Id.notificationbutton3);
            Button notificationButton4 = FindViewById<Button>(Resource.Id.notificationbutton4);
            Button notificationButton5 = FindViewById<Button>(Resource.Id.notificationbutton5);
            textView = FindViewById<TextView>(Resource.Id.textView2);


            notificationButtons = new Button[] { notificationButton1, notificationButton2, notificationButton3, notificationButton4, notificationButton5 };

            foreach (Button button in notificationButtons)
            {
                button.Enabled = false;
                button.Click += SendNotification;
            }            
		}
        protected override void OnResume()
        {
            base.OnResume();

            // LocationManagerを初期化
            locMgr = GetSystemService(Context.LocationService) as LocationManager;

            button.Click += (sender, e) =>
            {
                if (locMgr.AllProviders.Contains(LocationManager.NetworkProvider)
                        && locMgr.IsProviderEnabled(LocationManager.NetworkProvider))
                {
                    // Network: Wifiと3Gで位置情報を取得します。電池使用量は少ないですが精度にばらつきがあります。
                    Log.Debug(tag, "Starting location updates with Network");
                    locMgr.RequestLocationUpdates(LocationManager.NetworkProvider, 10000, 10, this);
                }
                else
                {
                    // GetBestProviderで最適なProviderを利用できるようです。(NetworkがあればそれがBestProviderになるようです。)
                    var locationCriteria = new Criteria();
                    locationCriteria.Accuracy = Accuracy.Coarse;
                    locationCriteria.PowerRequirement = Power.Medium;
                    string locationProvider = locMgr.GetBestProvider(locationCriteria, true);

                    Log.Debug(tag, "Starting location updates with " + locationProvider.ToString());
                    locMgr.RequestLocationUpdates(locationProvider, 10000, 10, this);
                }
            };
        }
		protected override void OnCreate (Bundle bundle)
		{
			base.OnCreate (bundle);

			AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionLocal;
			AndroidEnvironment.UnhandledExceptionRaiser +=  HandleAndroidException;
			Xamarin.Forms.Forms.Init (this, bundle);

			Forms.Init(this, bundle);
			FormsMaps.Init(this, bundle);

			_locationManager = GetSystemService (Context.LocationService) as LocationManager;
			Criteria locationCriteria = new Criteria();
			locationCriteria.Accuracy = Accuracy.Coarse;
			locationCriteria.PowerRequirement = Power.Medium;
			var locationProvider = _locationManager.GetBestProvider(locationCriteria, true);
			if(locationProvider != null)
			{
				_locationManager.RequestLocationUpdates (locationProvider, 500, 1, this);
			}

			var pclApp = App.Portable.App.Instance;
			var setup = new AppSetup () {
				CreateConnectionPool = this.CreateConnnectionPool,
				DbPath = Path.Combine (System.Environment.GetFolderPath (System.Environment.SpecialFolder.Personal),"RF12G5td864.db3")
			};
			pclApp.Setup (setup);
			#if DEBUG
			//pclApp.DeleteUser ();
			#endif
			LoadApplication (pclApp);
		}
 public GeoLocationService(LocationManager locationManager, IMarshalInvokeService marshalService)
 {
     manager = locationManager;
     marshal = marshalService;
     timer = new Timer(SEVEN_SECONDS);
     timer.Elapsed += OnTimeout;
 }
		protected override void OnResume ()
		{
			base.OnResume (); 

			// initialize location manager
			locMgr = GetSystemService (Context.LocationService) as LocationManager;
		}
Exemple #10
0
        public void start()
        {
            if (_tracking) return;

            var ls = (LocationManager) _context.GetSystemService(Context.LocationService);
            //var aproviders = ls.AllProviders.ToArray();
            //var hasGPS = ls.IsProviderEnabled(LocationManager.GpsProvider);
            //var hasNET = ls.IsProviderEnabled(LocationManager.NetworkProvider);

            //if (!hasGPS || !hasNET)
            {
                //throw new Exception("Must have both GPS and Net location providers");
            }

            _locationManager = ls;

            var lastLocation = _locationManager.GetLastKnownLocation(LocationManager.PassiveProvider);
            Location = createGeoLocation(lastLocation);

            var criteria = new Criteria();
            criteria.Accuracy = Accuracy.Fine;
            criteria.AltitudeRequired = true;

            var providers = _locationManager.GetProviders(criteria, true).ToArray();
            foreach (var provider in providers)
            {
                _locationManager.RequestLocationUpdates(provider, 1000, 5, _listener, Looper.MainLooper);
            }

            _tracking = true;
        }
        protected override void PlatformSpecificStart(MvxLocationOptions options)
        {
            if (_locationManager != null)
                throw new MvxException("You cannot start the MvxLocation service more than once");

            _locationManager = (LocationManager)Context.GetSystemService(Context.LocationService);
            if (_locationManager == null)
            {
                MvxTrace.Warning("Location Service Manager unavailable - returned null");
                SendError(MvxLocationErrorCode.ServiceUnavailable);
                return;
            }
            var criteria = new Criteria()
                {
                    Accuracy = options.Accuracy == MvxLocationAccuracy.Fine ? Accuracy.Fine : Accuracy.Coarse,
                };
            _bestProvider = _locationManager.GetBestProvider(criteria, true);
            if (_bestProvider == null)
            {
                MvxTrace.Warning("Location Service Provider unavailable - returned null");
                SendError(MvxLocationErrorCode.ServiceUnavailable);
                return;
            }

            _locationManager.RequestLocationUpdates(
                _bestProvider, 
                (long)options.TimeBetweenUpdates.TotalMilliseconds,
                options.MovementThresholdInM, 
                _locationListener);
        }
 protected override void GetCurrentLocation()
 {
     locationManager = context.GetSystemService(Context.LocationService) as LocationManager;
     if (locationManager.IsProviderEnabled(LocationManager.GpsProvider))
         locationManager.RequestLocationUpdates(LocationManager.GpsProvider, 2000, 1, this);
     
 }
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.Main);

            locationManager = GetSystemService(Context.LocationService) as LocationManager;

            //set the user current location
            setlocation();

            //setup the map
            SetupMap();


            //set left drawer staff
            leftDrawerLayaout = FindViewById<DrawerLayout>(Resource.Id.myDrawer);
            leftDrawer = FindViewById<ListView>(Resource.Id.leftListView);

            //get users 
            populateUsersOnDrawer();

            leftDrawerToggle = new ActionBarDrawerToggle(this, leftDrawerLayaout, Resource.Drawable.menu, Resource.String.drawer_open, Resource.String.drawer_close);
            leftDrawerLayaout.SetDrawerListener(leftDrawerToggle);
            ActionBar.SetDisplayHomeAsUpEnabled(true);
            ActionBar.SetHomeButtonEnabled(true);
            ActionBar.SetDisplayShowTitleEnabled(true);
           
            //start message service 
            StartService(new Intent(this, typeof(MsgApiService)));

        }
		protected override void OnResume ()
		{
			base.OnResume ();

			// Get a handle on the map element
			_mapFragment = FragmentManager.FindFragmentById(Resource.Id.map) as MapFragment;
			_map = _mapFragment.Map;

			// Set the map type 
			_map.MapType = GoogleMap.MapTypeNormal;

			// show user location
			_map.MyLocationEnabled = true;

			// setup a location manager
			_locationManager = GetSystemService(Context.LocationService) as LocationManager;

			// Add points on the map
			MarkerOptions marker1 = new MarkerOptions()
				.SetPosition(Location_Xamarin)
				.SetTitle("Xamarin")
				.InvokeIcon(BitmapDescriptorFactory.DefaultMarker(BitmapDescriptorFactory.HueBlue));
			_map.AddMarker(marker1);

			MarkerOptions marker2 = new MarkerOptions()
			    .SetPosition(Location_Atlanta)
			    .SetTitle("Atlanta, GA")
			    .InvokeIcon(BitmapDescriptorFactory.DefaultMarker(BitmapDescriptorFactory.HueRed));
			_map.AddMarker(marker2);

			// Add custom marker images on the map
			AddMonkeyMarkersToMap();

			// Add custom arrow callout on map
			AddInitialNewYorkBarToMap();

			// Add custom overlay image on the map
			PositionChicagoGroundOverlay(Location_Chicago);

			// use a generic location provider instead
			Criteria locationCriteria = new Criteria();
			locationCriteria.Accuracy = Accuracy.Coarse;
			locationCriteria.PowerRequirement = Power.Medium;

			var locationProvider = _locationManager.GetBestProvider(locationCriteria, true);
			if (locationProvider != null)
			{
				_locationManager.RequestLocationUpdates(locationProvider, 2000, 1, this);
			} else
			{
				Log.Info("error", "Best provider is not available. Does the device have location services enabled?");
			}

			// TODO: Step 4a - attach map handler for marker touch
//            _map.MarkerClick += MapOnMarkerClick;

			// TODO: Step 4c - attach map handler for info window touch
//			_map.InfoWindowClick += HandleInfoWindowClick;
		}
Exemple #15
0
		protected override void OnCreate (Bundle savedInstanceState)
		{
			base.OnCreate (savedInstanceState);

			logoImage = new UIImageView (this);
			logoImage.ImageResource = Resource.Drawable.esilehe_logo;
			logoImage.SetScaleType (ImageView.ScaleType.CenterInside);
			logoImage.LayoutParameters = LayoutUtils.GetRelativeMatchParent ();

			menuImageContainer = new UIView (this);
			menuImageContainer.Frame = new Frame (
				0,
				0,
				DeviceInfo.NavigationBarHeight + Sizes.ActionBarButtonSize,
				DeviceInfo.NavigationBarHeight
			);

			menuImage = new UIImageView (this);
			menuImage.ImageResource = Resource.Drawable.burger;
			menuImage.SetScaleType (ImageView.ScaleType.CenterInside);
			menuImage.Frame = new Frame (
				0,
				(menuImageContainer.Frame.H - Sizes.ActionBarButtonSize) / 2,
				Sizes.ActionBarButtonSize,
				Sizes.ActionBarButtonSize
			);

			menuImageContainer.AddView (menuImage);

			actionBarContainer = new UIView (this);
			actionBarContainer.Frame = new Frame (DeviceInfo.ScreenWidth, DeviceInfo.NavigationBarHeight);
			actionBarContainer.AddViews (
				logoImage,
				menuImageContainer
			);

			ActionBar.SetDisplayShowCustomEnabled (true);

			this.ActionBar.SetCustomView (
				actionBarContainer, 
				new ActionBar.LayoutParams (DeviceInfo.ScreenWidth, DeviceInfo.NavigationBarHeight)
			);




			locMgr = GetSystemService (Context.LocationService) as LocationManager;




			contentView = new MainView (this);
			SetContentView (contentView);

			menuPopup = new MenuPopupView (this, WindowManager);
			menuPopup.UpdateView ();

			menuImageContainer.Click += (object sender, System.EventArgs e) => ShowMenu ();
		}
 public LocationProvider(Context context, ILocationListener locListener)
 {
     this.context = context;
     this.locationManager = LocationManager.FromContext (context);
     this.locationListener = locListener;
     this.gpsProviderEnabled = this.locationManager.IsProviderEnabled (LocationManager.GpsProvider);
     this.networkProviderEnabled = this.locationManager.IsProviderEnabled (LocationManager.NetworkProvider);
 }
Exemple #17
0
 public Locator(Activity ctx)
 {
     this.ctx = ctx;
     locationManager = (LocationManager)ctx.GetSystemService (Context.LocationService);
     locationManager.RequestLocationUpdates (LocationManager.PassiveProvider, 5 * 60 * 1000, 2, this);
     if (Geocoder.IsPresent)
         geocoder = new Geocoder (ctx);
 }
 public Geolocation(LocationManager locationManager)
 {
     _locationManager = locationManager;
     _success = position => { };
     _error = error => { };
     _options= new GeolocationOptions();
     _watchId = Guid.NewGuid().ToString();
 }
 private void EnsureStopped()
 {
     if (_locationManager != null)
     {
         _locationManager.RemoveUpdates(_locationListener);
         _locationManager = null;
     }
 }
 private void InitializeLocationManager()
 {
     _locationManager = (LocationManager)GetSystemService(LocationService);
     var kriteria = new Criteria { Accuracy = Accuracy.Fine };
     var accepatbleLocationProvs = _locationManager.GetProviders(kriteria, true);
     _locationProvider = accepatbleLocationProvs.Any() ? accepatbleLocationProvs.First() : string.Empty;
     Log.Debug(TAG, "using : " + _locationProvider + ".");
 }
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            SetContentView(Resource.Layout.LocationView);

            // use location service directly
            _locMgr = GetSystemService(LocationService) as LocationManager;
        }
Exemple #22
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            global::Xamarin.Forms.Forms.Init(this, bundle);
            global::Xamarin.FormsMaps.Init(this, bundle);
            locationManager = GetSystemService(Context.LocationService) as LocationManager;

            LoadApplication(new App());
        }
Exemple #23
0
 //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 //Check if GPS Enabled
 public static bool IsGPSProviderEnabled(LocationManager pLocMgr)
 {
     if (pLocMgr.IsProviderEnabled(LocationManager.GpsProvider))
       {
     return true;
       }
       else
       {
     return false;
       }
 }
        public LocationTestService(Context context)
        {
            locationManager = (LocationManager)context.GetSystemService(Context.LocationService);
            var criteriaForLocationService = new Criteria { Accuracy = Accuracy.Fine };
            var acceptableLocationProviders = locationManager.GetProviders(criteriaForLocationService, true);

            if (acceptableLocationProviders.Any())
            {
                locationProvider = acceptableLocationProviders.First();
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="T:MyCareManager.Droid.Geolocation.LocationManager"/> class.
        /// </summary>
        public LocationManager()
        {
            LocationUpdates = new Subject <LocationUpdatedEventArgs>();

            _locMgr    = (Android.Locations.LocationManager)Application.Context.GetSystemService(Context.LocationService);
            _providers = _locMgr.GetProviders(false)
                         .Where(s => s != Android.Locations.LocationManager.PassiveProvider)
                         .ToArray();

            _geolocationListener = new GeolocationListener();
        }
      public Geolocator( Context context )
      {
         if(context == null)
         {
            throw new ArgumentNullException( "context" );
         }

         manager = (LocationManager)context.GetSystemService( Context.LocationService );
         providers =
            manager.GetProviders( enabledOnly: false ).Where( s => s != LocationManager.PassiveProvider ).ToArray();
      }
        public static GPSHelper GetInstance()
        {
            if (_helper == null)
            {
                _helper = new GPSHelper();
                _myLocationManager = (LocationManager)EmployeeManagement._context.GetSystemService(Android.Content.Context.LocationService);
                GPSHelper.startGpsListener();
                _curLocation = new Location("default");
            }

            return _helper;
        }
        public GeolocationContinuousListener(LocationManager manager, TimeSpan timePeriod, IList<string> providers)
        {
            this.manager = manager;
            this.timePeriod = timePeriod;
            this.providers = providers;

            foreach (string p in providers)
            {
                if (manager.IsProviderEnabled(p))
                    this.activeProviders.Add(p);
            }
        }
Exemple #29
0
		void InitializeLocationManager()
		{
			locMgr = GetSystemService (Context.LocationService) as LocationManager;

			if (locMgr.AllProviders.Contains (LocationManager.NetworkProvider)
				&& locMgr.IsProviderEnabled (LocationManager.NetworkProvider)) {
				locMgr.RequestLocationUpdates (LocationManager.NetworkProvider, 0, 0, this);
			} else {
				MApplication.getInstance().longitude = 0;
				MApplication.getInstance().latitude = 0;
			}
		}
        /// <summary>
        /// Creates the event for the home activity.
        /// Sets layout to home_page, references the Find Nearby Users,
        /// Get Location and Edit Profile button clicks.
        /// </summary>
        /// <param name="bundle">Bundle.</param>
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the home_page resource
            SetContentView(Resource.Layout.home_page);

            // Set context to this activity to be passed to NearbyUsersFragment
            Config.context = this;

            // Get profile object from another activity
            var jsonString = Intent.GetStringExtra("UserProfile");
            userProfile = JsonConvert.DeserializeObject<Profile>(jsonString);

            // Set our view from the home_page resource
            SetContentView(Resource.Layout.home_page);

            // References for Home Menu Items
            mButtonNearbyUsers = FindViewById<Button>(Resource.Id.NearbyUsersButton);
            mButtonUpdateLocation = FindViewById<Button>(Resource.Id.SetLocationButton);
            mButtonSendMessage = FindViewById<Button>(Resource.Id.SendMessageButton);
            mButtonGroupSendMessage = FindViewById<Button>(Resource.Id.btnGroupMessage);
            mTextViewUsername = FindViewById<TextView>(Resource.Id.UsernameTextView);


            // Set username text
            mTextViewUsername.Text = userProfile.username;

            //*** Click Events ***
            // Find Nearby Users Click
            mButtonNearbyUsers.Click += delegate
            {
                StartActivity(typeof(NearbyUsersActivity));
            };

            // Set Current Location Click 
            mButtonUpdateLocation.Click += mButtonSetLocation_Click;

            // Send Message Click
            mButtonSendMessage.Click += MButtonSendMsg_Click;

            //Send Group Message Click
            mButtonGroupSendMessage.Click += MButtonGroupSendMessage_Click;

            // Get the location manager
            locationManager = (LocationManager)GetSystemService(Context.LocationService);

            // Define the criteria how to select the location provider
            Criteria criteria = new Criteria();
            criteria.Accuracy = Accuracy.Fine;
            provider = locationManager.GetBestProvider(criteria, true);
        }
Exemple #31
0
		protected override void OnCreate(Bundle bundle)
		{
			base.OnCreate(bundle);
			SetContentView(Resource.Layout.Main);
			ConnectivityManager connectivityManager = (ConnectivityManager) GetSystemService(ConnectivityService);
			NetworkInfo activeConnection = connectivityManager.ActiveNetworkInfo;


			Button loginButton = FindViewById<Button>(Resource.Id.loginButton);
			Button filteButton = FindViewById<Button> (Resource.Id.button1);
 			prefs = PreferenceManager.GetDefaultSharedPreferences(this);
			_locationManager = GetSystemService (Context.LocationService) as LocationManager;
			Criteria criteriaForLocationService = new Criteria
			{
				Accuracy = Accuracy.Fine
			};
			acceptableLocationProviders = _locationManager.GetProviders(criteriaForLocationService, true);

				
				filteButton.Click += (object sender, EventArgs e) => {
					Intent intent = new Intent (this, typeof(FilterActivity));
					StartActivityForResult (intent, 0);
				};

				loginButton.Click += (object sender, EventArgs e) => {
				bool isOnline = (activeConnection != null) && activeConnection.IsConnected;
				bool wifiIsOnline = (connectivityManager.GetNetworkInfo(ConnectivityType.Wifi)).IsConnected;
				if (isOnline || wifiIsOnline) {
					
					if (!string.IsNullOrEmpty (prefs.GetString ("token", ""))) {
						Intent intent = new Intent (this, typeof(SearchActivity));
						StartActivityForResult (intent, 0);
					} else {
						auth = Global.LogIn ();
						auth.Completed += auth_Completed;
						StartActivity (auth.GetUI (this));
					}
				}
				else 
				{
					AlertDialog.Builder alert = new AlertDialog.Builder (this);
					alert.SetTitle ("Internet connection error");
					alert.SetMessage ("Turn wifi or mobile data on");
					alert.SetPositiveButton ("Ok", (senderAlert, args) => {

					});
					Dialog dialog = alert.Create();
					dialog.Show();
				}
			};
		
			} 
        protected override void OnResume()
        {
            base.OnResume ();

            locMgr = GetSystemService (Context.LocationService) as LocationManager;

            if (locMgr.AllProviders.Contains (LocationManager.NetworkProvider)
                && locMgr.IsProviderEnabled (LocationManager.NetworkProvider)) {
                locMgr.RequestLocationUpdates (LocationManager.NetworkProvider, 2000, 1, this);
            } else {
                Toast.MakeText (this, "The Network Provider does not exist or is not enabled!", ToastLength.Long).Show ();
            }
        }
        private PhoneRequirements CheckLocationRequirements()
        {
            _locationManager = (LocationManager)GetSystemService(LocationService);
            _connectivityManager = (ConnectivityManager)GetSystemService(ConnectivityService);

            var internetAccess = _connectivityManager.ActiveNetworkInfo;

            return new PhoneRequirements()
            {
                Gps = _locationManager.IsProviderEnabled(LocationManager.GpsProvider),
                Network = _locationManager.IsProviderEnabled(LocationManager.NetworkProvider),
                Internet = internetAccess != null && internetAccess.IsConnected
            };
        }
Exemple #34
0
        protected override void OnCreate(Bundle bundle)
        {
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource   = Resource.Layout.Toolbar;

            base.OnCreate(bundle);

            //...

            Xamarin.Essentials.Platform.Init(this, bundle); // add this line to your code, it may also be called: bundle
            //...

            global::Xamarin.Forms.Forms.Init(this, bundle);

            if (ContextCompat.CheckSelfPermission(this, Manifest.Permission.AccessFineLocation) != Permission.Granted)
            {
                List <string> permission = new List <string>();
                permission.Add(Manifest.Permission.AccessFineLocation);

                if (permission.Count > 0)
                {
                    string[] array = permission.ToArray();

                    RequestPermissions(array, array.Length);
                }
            }

            try
            {
                locationManager = GetSystemService("location") as LocationManager;
                string Provider = LocationManager.GpsProvider;

                if (locationManager.IsProviderEnabled(Provider))
                {
                    locationManager.RequestLocationUpdates(Provider, 2000, 1, this);
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
            LoadApplication(new App());
        }
Exemple #35
0
        void InitializeLocationManager()
        {
            _locationManager = (LocationManager)GetSystemService(LocationService);
            Criteria criteriaForLocationService = new Criteria
            {
                Accuracy = Accuracy.Fine
            };
            IList <string> acceptableLocationProviders = _locationManager.GetProviders(criteriaForLocationService, true);

            if (acceptableLocationProviders.Count > 0)
            {
                _locationProvider = acceptableLocationProviders[0];
                _locationManager.RequestLocationUpdates(_locationProvider, 0, 0, this);
                // Toast.MakeText(this, " Location provider  " + acceptableLocationProviders[0], ToastLength.Short).Show();
            }
            else
            {
                _locationProvider = String.Empty;
            }
        }
Exemple #36
0
 public LocationManager()
 {
     _locationManager  = (ALocationManager)Application.Context.GetSystemService(Context.LocationService);
     _providers        = _locationManager.GetProviders(false).ToArray();
     _ignoredProviders = new[] { ALocationManager.PassiveProvider, "local_database" };
 }