Exemplo n.º 1
0
        protected override void OnPause()
        {
            base.OnPause();

            if (locationInitialised)
            {
                _locationManager.RemoveUpdates(this);
            }
        }
Exemplo n.º 2
0
        public void StopLocationUpdates()
        {
            var providers = ListeningProviders;

            for (var i = 0; i < providers.Count; i++)
            {
                try
                {
                    _locationManager.RemoveUpdates(this);
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine("Unable to remove updates: " + ex);
                }
            }
        }
Exemplo n.º 3
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";
                }

            };
        }
Exemplo n.º 4
0
 /// <summary>
 /// Stops the location update.
 /// </summary>
 public void StopLocationUpdate()
 {
     locationManager.RemoveUpdates(this);
 }