// 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)
                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();
                }


                // 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);*/
            };
        }
예제 #2
0
        // OnResume gets called every time the activity starts, so we'll put our RequestLocationUpdates
        // code here, so that
        protected override void OnResume()
        {
            base.OnResume();


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

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


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