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);
                }
            };
        }
		public Location GetLocation() {
			try {
				locationManager = (LocationManager)mContext.GetSystemService("location");

				// Getting GPS status
				isGPSEnabled = locationManager.IsProviderEnabled(LocationManager.GpsProvider);

				// Getting network status
				isNetworkEnabled = locationManager.IsProviderEnabled(LocationManager.NetworkProvider);

				if (!isGPSEnabled && !isNetworkEnabled) {
					//showalert in activity
				}
				else {
					this.CanGetLocation = true;
					if (isNetworkEnabled) {
						locationManager.RequestLocationUpdates(
								LocationManager.NetworkProvider,
								MIN_TIME_BW_UPDATES,
								MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
						if (locationManager != null) {
							location = locationManager.GetLastKnownLocation(LocationManager.NetworkProvider);
							if (location != null) {
								latitude = location.Latitude;
								longitude = location.Longitude;
							}
						}
					}
					if (isGPSEnabled) {
						if (location == null) {
							locationManager.RequestLocationUpdates(
									LocationManager.GpsProvider,
									MIN_TIME_BW_UPDATES,
									MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
							if (locationManager != null) {
								location = locationManager.GetLastKnownLocation(LocationManager.GpsProvider);
								if (location != null) {
									latitude = location.Latitude;
									longitude = location.Longitude;
								}
							}
						}
					}
				}
			} catch (Exception e) {
				AlertsService.ShowToast(this.mContext, "Nie masz w³¹czonej lokalizacji!");
			}

			return location;
		}
示例#3
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;
        }
		// OnResume gets called every time the activity starts, so we'll put our RequestLocationUpdates
		// code here, so that 
		protected override void OnResume ()
		{
			base.OnResume (); 
			Log.Debug (tag, "OnResume called");

			// initialize location manager
			locMgr = GetSystemService (Context.LocationService) as LocationManager;

			button.Click += delegate {
				button.Text = "Location Service Running";

				// pass in the provider (GPS), 
				// the minimum time between updates (in seconds), 
				// the minimum distance the user needs to move to generate an update (in meters),
				// and an ILocationListener (recall that this class impletents the ILocationListener interface)
				locMgr.RequestLocationUpdates (LocationManager.NetworkProvider, 2000, 1, this);


				// Comment the line above, and uncomment the following, to test 
				// the GetBestProvider option. This will determine the best provider
				// at application launch. Note that once the provide has been set
				// it will stay the same until the next time this method is called

				/*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, 2000, 1, this);*/
			};
		}
示例#5
0
        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 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);
            }
        }
        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);
     
 }
示例#9
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);
            }
        }
示例#10
0
		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);
		}
示例#11
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);
 }
示例#12
0
 protected override void OnResume()
 {
     base.OnResume();
     if (locationInitialised)
     {
         _locationManager.RequestLocationUpdates(_locationProvider, 0, 0, this);
     }
 }
		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;

			// TODO: Step 3b - 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);

			// TODO: Step 3c - Add custom marker images on the map
//            AddMonkeyMarkersToMap();

			// TODO: Step 3d - Add custom arrow callout on map
//            AddInitialNewYorkBarToMap();

			// TODO: Step 3e - 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?");
			}
		}            
示例#14
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;
			}
		}
        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 ();
            }
        }
        public void StartService()
        {
            _locMan = Application.Context.GetSystemService (Context.LocationService) as LocationManager;

            if (_locMan.GetProvider (LocationManager.GpsProvider) != null && _locMan.IsProviderEnabled (LocationManager.GpsProvider))
            {
                _pi = PendingIntent.GetBroadcast(Application.Context, 0, new Intent(), PendingIntentFlags.UpdateCurrent);
                _locMan.RequestLocationUpdates(LocationManager.GpsProvider, 2000, 5, _pi);
                _locMan.GetLastKnownLocation (LocationManager.GpsProvider);
            }

            else
                throw new GPSNotEnabledException (Const.NO_GPS_ERROR_MESSAGE);
        }
		/// <summary>
		/// This method activates the Android LocationManager and begins reporting
		/// location changes through our own LocationChanged event.
		/// </summary>
		public void StartLocationUpdates()
		{
			locMgr = Application.Context.GetSystemService("location") as LocationManager;
			if (locMgr == null)
				return;

			var locationCriteria = new Criteria() {
				Accuracy = Accuracy.NoRequirement,
				PowerRequirement = Power.NoRequirement
			};

			var locationProvider = locMgr.GetBestProvider(locationCriteria, true);
			locMgr.RequestLocationUpdates(locationProvider, 2000, 0, this);
		}
示例#18
0
		public override void OnStart (Android.Content.Intent intent, int startId)
		{
			base.OnStart (intent, startId);

			DBRepository dbr = new DBRepository ();
			userAndsoft = dbr.getUserAndsoft ();
			userTransics = dbr.getUserTransics ();

			var t = DateTime.Now.ToString("dd_MM_yy");
			string dir_log = (Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryDownloads)).ToString();
			ISharedPreferences pref = Application.Context.GetSharedPreferences("AppInfo", FileCreationMode.Private);
			string log = pref.GetString("Log", String.Empty);
			//GetTelId
			TelephonyManager tel = (TelephonyManager)this.GetSystemService(Context.TelephonyService);
			var telId = tel.DeviceId;

			//Si il n'y a pas de shared pref
			if (log == String.Empty){
				log_file = Path.Combine (dir_log, t+"_"+telId+"_log.txt");
				ISharedPreferencesEditor edit = pref.Edit();
				edit.PutString("Log",log_file);
				edit.Apply();
			}else{
				//il y a des shared pref
				log_file = pref.GetString("Log", String.Empty);
				if (((File.GetCreationTime(log_file)).CompareTo(DateTime.Now)) > 3) {
					File.Delete(log_file);
					log_file = Path.Combine (dir_log, t+"_"+telId+"_log.txt");
					ISharedPreferencesEditor edit = pref.Edit();
					edit.PutString("Log",log_file);
					edit.Apply();
					log_file = pref.GetString("Log", String.Empty);
				}

			}
			File.AppendAllText(log_file,"[SERVICE] Service Onstart call "+DateTime.Now.ToString("t")+"\n");
			DoStuff ();

			// initialize location manager
			locMgr = GetSystemService (Context.LocationService) as LocationManager;

			if (locMgr.AllProviders.Contains (LocationManager.NetworkProvider)
				&& locMgr.IsProviderEnabled (LocationManager.NetworkProvider)) {
				locMgr.RequestLocationUpdates (LocationManager.NetworkProvider, 2000, 1, this);
				File.AppendAllText(log_file,"[GPS] Lancer le"+DateTime.Now.ToString("t")+"\n");
			} else {
				File.AppendAllText(log_file,"[GPS] Le GPS est désactiver"+DateTime.Now.ToString("t")+"\n");
			}
		}
        public override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate (savedInstanceState);

            // Create your fragment here
            string lp = string.Empty;
            _lm = (LocationManager) GetSystemService(LocationService);
            Criteria cr = new Criteria { Accuracy = Accuracy.Fine };
            IList<string> alp = _lm.GetProviders (cr, true);

            if (alp.Any ()) {
                lp = alp.First ();
                _lm.RequestLocationUpdates (lp, this);
            }
        }
        public void StartLocationManager(Action<MyLocation> callBack)
        {
            manager = (LocationManager) Android.App.Application.Context.GetSystemService (Context.LocationService);

            _callBack = callBack;

            Criteria criteriaForLocationService = new Criteria { Accuracy = Accuracy.Coarse };

            IList<string> acceptableLocationProviders = manager.GetProviders(criteriaForLocationService, true);

            if (acceptableLocationProviders.Any())
                manager.RequestLocationUpdates (acceptableLocationProviders.First (), 0, 0, this);
            else
                throw new LocationServiceNotRunningException ();
        }
示例#21
0
        public void GetLocation()
        {
            _locationManager = Application.Context.GetSystemService(Context.LocationService) as LocationManager;

            var 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);
            }
        }
示例#22
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());
        }
示例#23
0
        public override StartCommandResult OnStartCommand(Android.Content.Intent intent, StartCommandFlags flags, int startId)
        {
            locMgr = GetSystemService(Context.LocationService) as LocationManager;

            if (locMgr.AllProviders.Contains(LocationManager.NetworkProvider)
                && locMgr.IsProviderEnabled(LocationManager.NetworkProvider))
            {
                locMgr.RequestLocationUpdates(LocationManager.NetworkProvider, 2000, 1, this);
            }
            else
            {
                API apiCall = new API();
                apiCall.addReport("GPS is disabled");
                StopSelf();

            }

            return StartCommandResult.NotSticky;
        }
示例#24
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;
            }
        }
 /// <summary>
 /// Starts the location update.
 /// </summary>
 /// <param name="precision">Précision en mêtre.</param>
 public void StartLocationUpdate(double precision)
 {
     if (GetLocationPermission())
     {
         Precision = precision;
         var accuracy = precision <= 10 ? Accuracy.Fine : Accuracy.Coarse;
         Provider = locationManager.GetBestProvider(new Criteria()
         {
             PowerRequirement = Power.NoRequirement, Accuracy = accuracy
         }, true);
         if (Provider != null)
         {
             locationManager.RequestLocationUpdates(Provider, 1, distanceFilter, this);
         }
         else
         {
             System.Diagnostics.Debug.WriteLine("No provider available. Does the device have location services enabled?");
         }
     }
 }
示例#26
0
        public void RequestLocationUpdates()
        {
            if (!IsGeolocationEnabled)
            {
                return;
            }

            var providers = _providers;
            var looper    = Looper.MyLooper() ?? Looper.MainLooper;

            ListeningProviders.Clear();
            foreach (var provider in providers)
            {
                if (_ignoredProviders.Contains(provider))
                {
                    continue;
                }

                ListeningProviders.Add(provider);
                _locationManager.RequestLocationUpdates(provider, 1000, 0, this, looper);
            }
        }
        public void InitLocationService()
        {
            var wrapper = new Android.Content.ContextWrapper(Forms.Context);

            _locationManager = (LocationManager) wrapper.GetSystemService(Context.LocationService);
            Criteria criteriaForLocationService = new Criteria
            {
                Accuracy = Accuracy.Fine
            };
            IList<string> acceptableLocationProviders = _locationManager.GetProviders(criteriaForLocationService, true);

            if (acceptableLocationProviders.Any())
            {
                _locationProvider = acceptableLocationProviders.First();
                _locationManager.RequestLocationUpdates(_locationProvider, 2000, 10, this);
            }
            else
            {
                _locationProvider = String.Empty;
            }
            Console.WriteLine("Using " + _locationProvider + ".");
        }
        protected override void OnResume ()
        {
            base.OnResume ();

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

			#region Show Location
			// TODO: Step 2a - show user location
			 _map.MyLocationEnabled = true;

			_map.UiSettings.MyLocationButtonEnabled = true;
			#endregion

			#region Setup Location Manager

			// TODO: Step 2b - setup a location manager
			 _locationManager = GetSystemService(Context.LocationService) as LocationManager;

			#endregion

			#region Get Location Provider 

			// TODO: Step 2d - use a generic location provider
			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);
			} 

			#endregion

        }
        protected override void PlatformSpecificStart(MvxGeoLocationOptions 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.EnableHighAccuracy ? Accuracy.Fine : Accuracy.Coarse};
            var bestProvider = _locationManager.GetBestProvider(criteria, true);
            if (bestProvider == null)
            {
                MvxTrace.Warning( "Location Service Provider unavailable - returned null");
                SendError(MvxLocationErrorCode.ServiceUnavailable);
                return;
            }
            _locationManager.RequestLocationUpdates(bestProvider, 5000, 2, _locationListener);
            // TODO - Ideally - _geoWatcher.MovementThreshold needed too
        }
        protected override void OnResume ()
        {
            base.OnResume ();

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

			 _map.UiSettings.MyLocationButtonEnabled = true;
			 _map.MyLocationEnabled = true;

			 _locationManager = GetSystemService(Context.LocationService) as LocationManager;

//			string Provider = LocationManager.GpsProvider;
//			if(_locationManager.IsProviderEnabled(Provider))
//			{
//			    _locationManager.RequestLocationUpdates (Provider, 2000, 1, this);
//			} 
//			else 
//			{
//			    Log.Info("error", Provider + " is not available. Does the device have location services enabled?");
//			}

			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?");
			}
        }
示例#31
0
        public override void OnStart(Android.Content.Intent intent, int startId)
        {
            base.OnStart (intent, startId);
            //base.OnStartCommand(intent,StartCommandFlags.Redelivery,startId);

            settingsFile = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
            settingsFile = Path.Combine(settingsFile, "settings.txt");

            if (File.Exists (settingsFile)) {
                SettingsRecord settings =  JsonConvert.DeserializeObject<SettingsRecord>( File.ReadAllText(settingsFile));
                timeBetweenUpdates = settings.timeBetweenUpdates;
                timeBetweenUpdatesDense = settings.timeBetweenUpdatesDense;
                speedLimit = settings.speedLimit;
            }

            locMgr = GetSystemService (Context.LocationService) as LocationManager;
            locMgr.RequestLocationUpdates (LocationManager.NetworkProvider, timeBetweenUpdates , 0, this);

            locationsFile = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
            locationsFile = Path.Combine(locationsFile, "locations.txt");

            if (File.Exists (locationsFile)) {
                List<string> lines = new List<string> (File.ReadLines (locationsFile));
                if (lines.Count > 0) {
                    lastRecord = JsonConvert.DeserializeObject<LocationRecord> (lines [lines.Count - 1]);
                }

            //				if (lines.Count >= maxLineCount) {
            //					int i;
            //					StreamWriter sw = new StreamWriter (locationsFile, false);
            //					for (i = 2/3 * maxLineCount; i < lines.Count; i++) {
            //						sw.WriteLine (lines [i]);
            //					}
            //					sw.Close ();
            //				}
            }
        }
示例#32
0
        protected override void OnResume()
        {
            base.OnResume();

            locMgr = GetSystemService(Context.LocationService) as LocationManager;

#if DEBUG
            // 利用可能な LocationManager の Provider とオンオフをチェック
            foreach (var item in locMgr.AllProviders)
            {
                Log.Debug("NetworkList", "Provider: " + item.ToString());
                Log.Debug("NetworkList", "Avalable: " + locMgr.IsProviderEnabled(item.ToString()));
            }
#endif

            button.Click += (sender, e) =>
            {
                if (button.Text.ToUpper() == "GET LOCATION")
                {
                    button.Text = "Location Service Running";

                    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 があればそれが Best になるようです。)
                        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);
                    }
                }
                else
                {
                    Log.Debug(tag, "Stop locMgr manually");
                    locMgr.RemoveUpdates(this);
                    button.Text = "Get Location";
                }

            };
        }
示例#33
0
        private void InitializeLocationManager()
        {
            _locationManager = (LocationManager)GetSystemService(LocationService);
            var criteriaForLocationService = new Criteria
            {
                Accuracy = Accuracy.Coarse,
                PowerRequirement = Power.Medium
            };

            LocationProvider = _locationManager.GetBestProvider(criteriaForLocationService, true);
            _locationManager.RequestLocationUpdates(LocationProvider, 120000, 5000, this);
        }
示例#34
0
        private void InitLocation()
        {
            try
            {
                _locationManager = (LocationManager)_context.GetSystemService(LocationService);

                // getting GPS status
                _isGPSEnabled = _locationManager.IsProviderEnabled(LocationManager.GpsProvider);

                // getting network status
                _isNetworkEnabled = _locationManager.IsProviderEnabled(LocationManager.NetworkProvider);

                if (!_isGPSEnabled && !_isNetworkEnabled)
                {
                    // no network provider is enabled
                }
                else
                {
                    this._canGetLocation = true;
                    if (_isNetworkEnabled)
                    {
                        _locationManager.RequestLocationUpdates(LocationManager.NetworkProvider,
                            MIN_TIME_BW_UPDATES,
                            MIN_DISTANCE_CHANGE_FOR_UPDATES,
                            this);

                        Log.Debug("Network", "Network Enabled");

                        if (_locationManager != null)
                        {
                            _location = _locationManager.GetLastKnownLocation(LocationManager.NetworkProvider);

                            if (_location != null)
                            {
                                _latitude = _location.Latitude;
                                _longitude = _location.Longitude;
                            }
                        }
                    }

                    // if GPS Enabled get lat/long using GPS Services
                    if (_isGPSEnabled)
                    {
                        if (_location == null)
                        {
                            _locationManager.RequestLocationUpdates(
                                    LocationManager.GpsProvider,
                                    MIN_TIME_BW_UPDATES,
                                    MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
                            Log.Debug("GPS", "GPS Enabled");

                            if (_locationManager != null)
                            {
                                _location = _locationManager.GetLastKnownLocation(LocationManager.GpsProvider);
                                if (_location != null)
                                {
                                    _latitude = _location.Latitude;
                                    _longitude = _location.Longitude;
                                }
                            }
                        }
                    }
                }

            }
            catch (Exception e)
            {
                Log.Error("Location Error", e.StackTrace);
            }
        }
		//ON RESUME
		protected override void OnResume ()
		{
			base.OnResume (); 
			Log.Debug (tag, "OnResume called");

			// initialize location manager
			locMgr = GetSystemService (Context.LocationService) as LocationManager;

				var locationCriteria = new Criteria();

				locationCriteria.Accuracy = Accuracy.Coarse;
				locationCriteria.PowerRequirement = Power.Medium;

				string locationProvider = locMgr.GetBestProvider(locationCriteria, true);
				string prov=locationProvider.ToString();

				if(prov=="passive"){
					Log.Debug(tag, "Están deshabilitados los proveedores de ubicación: " + locationProvider.ToString());
					Toast.MakeText (this, "The Network Provider does not exist or is not enabled!", ToastLength.Long).Show ();
				gpsclass.PutString ("latitud", "nogps");
				gpsclass.PutString ("longitud", "nogps");
				}else{
					Log.Debug(tag, "Starting location updates with " + locationProvider.ToString());
					locMgr.RequestLocationUpdates (locationProvider, 2000, 0, this);
				}

			//Last Known Location
			Log.Debug(tag, "Se obtiene la ultima localizacion conocida");

			//locMgr.GetLastKnownLocation(locationProvider)

			try{
			Log.Debug ("LastKnownLocation","Latitud: "+locMgr.GetLastKnownLocation(locationProvider).Latitude+" Longitud: "+locMgr.GetLastKnownLocation(locationProvider).Longitude);
			}catch(NullReferenceException ex){
			Log.Debug ("LastKnownLocation","No hay LastLocation disponible");
			}
		}
示例#36
0
        private void AcquireCurrentGeoLocation()
        {
            _locationManager = (LocationManager)Application.Context.GetSystemService(Context.LocationService);
            // Get the best location provider
            Criteria locationCriteria = new Criteria();
            locationCriteria.Accuracy = Accuracy.Coarse;
            locationCriteria.PowerRequirement = Power.Medium;
            var locationProvider = _locationManager.GetBestProvider(locationCriteria, true);

            if (locationProvider != null)
            {
                CurrentLocation = _locationManager.GetLastKnownLocation(locationProvider);
            }

            _locationManager.RequestLocationUpdates(locationProvider, 0, 0, _locationListener);
        }
 void InitializeLocationManager()
 {
     _locationManager = (LocationManager)GetSystemService(LocationService);
     var criteriaForLocationService = new Criteria { Accuracy = Accuracy.Fine };
     IList<string> acceptableLocationProviders = _locationManager.GetProviders(criteriaForLocationService, true);
     _locationProvider = acceptableLocationProviders.FirstOrDefault() ?? "";
     _locationManager.RequestLocationUpdates(_locationProvider, 5000, 100, this);
 }