Beispiel #1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            RequestWindowFeature(WindowFeatures.NoTitle);
            base.OnCreate(savedInstanceState);
            LocationManager tmp        = (LocationManager)GetSystemService(LocationService);
            var             GPSEnabled = tmp.IsProviderEnabled(Android.Locations.LocationManager.GpsProvider);

            if (!GPSEnabled)
            {
                Toast.MakeText(this, "GPS is disabled. It is required for the first start and to update position.", ToastLength.Long).Show();
            }

            SetContentView(Resource.Layout.Nodata);
        }
        /* Peut etre execute en synchrone car recupere uste la position*/
        public void GetLocationAsync(String p_Provider)
        {
            LocationManager l_LocationManager = GetLocationManager();


            Initialisation BDD = new Initialisation();

            BDD.DBConnection();

            var locationCriteria = new Criteria
            {
                Accuracy         = Accuracy.Fine,
                PowerRequirement = Power.Medium
            };
            var locationProvider = l_LocationManager.GetBestProvider(locationCriteria, true);

            l_LocationManager.RequestLocationUpdates(p_Provider, MIN_TIME_FOR_UPDATE, MIN_DISTANCE_FOR_UPDATE, locationListener);
            var GPSEnabled = l_LocationManager.IsProviderEnabled(p_Provider);

            if (GPSEnabled)
            {
                if (l_LocationManager != null)
                {
                    Localisation location = new Localisation();

                    Location p_location = getLastKnownLocation();
                    if (p_location != null)
                    {
                        BDD.BDDConnection.DeleteAll <Localisation>();
                        location.Latitude  = (float)p_location.Latitude;
                        location.Longitude = (float)p_location.Longitude;
                        BDD.BDDConnection.InsertOrIgnore(location);
                    }
                }
            }
            else
            {
                Toast.MakeText(this, "GPS is disabled. It is required for the first start and to update position.", ToastLength.Long).Show();
            }

            BDD.BDDConnection.Close();
            return;
        }