コード例 #1
0
        private async void TestB_Clicked(object sender, EventArgs e)
        {
            PermissionStatus status = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Location);

            if (status != PermissionStatus.Granted)
            {
                var results = await CrossPermissions.Current.RequestPermissionsAsync(new[] { Permission.Location });

                status = results[Permission.Location];

                if (status != PermissionStatus.Granted)
                {
                    string msg = "No tenemos acceso a tu posicion";
                    await DisplayAlert("Alerta", msg, "ok");

                    return;
                }
            }



            Plugin.Geolocator.Abstractions.IGeolocator locator = CrossGeolocator.Current;
            locator.DesiredAccuracy = 20;

            var position = await locator.GetPositionAsync();

            Time.Text = "Time: " + position.Timestamp.LocalDateTime.ToString();
            Lat.Text  = "Latitude: " + position.Latitude.ToString();
            Long.Text = "Longitude: " + position.Longitude.ToString();
        }
コード例 #2
0
        private async Task RetreiveLocation()
        {
            locator = CrossGeolocator.Current;
            locator.DesiredAccuracy = 50;

            if (locator.IsGeolocationAvailable && locator.IsGeolocationEnabled)
            {
                var position = await locator.GetPositionAsync(TimeSpan.FromSeconds(100));

                if (position == null)
                {
                    return;
                }

                Debug.WriteLine("Position Status: {0}", position.Timestamp);
                Debug.WriteLine("Position Latitude: {0}", position.Latitude.ToString());
                Debug.WriteLine("Position Longitude: {0}", position.Longitude.ToString());

                locator.PositionChanged += (sender, e) => {
                    position = e.Position;

                    Debug.WriteLine("Position Latitude: {0}", position.Latitude.ToString());
                    Debug.WriteLine("Position Longitude: {0}", position.Longitude.ToString());
                };
            }
            else
            {
                await DisplayAlert("Error", "Home", "OK");
            }
        }
コード例 #3
0
 public Feed()
 {
     InitializeComponent();
     manager = TableManager.DefaultManager;
     locator = CrossGeolocator.Current;
     RefreshItems(true, syncItems: false);
 }
コード例 #4
0
        //(CDLTLL) Constructor with injected dependencies
        public VehicleDetailsViewModel(IVehiclesService vehiclesService, Vehicle vehicle)
        {
            //Injected dependencies
            _vehiclesService = vehiclesService;
            _vehicle         = vehicle;

            _geolocator = Plugin.Geolocator.CrossGeolocator.Current;
        }
コード例 #5
0
        void StartService()
        {
            // Set up an intent so that tapping the notifications returns to this app:
            //  Intent intent = new Intent(this, typeof(MainApplication));

            // Create a PendingIntent; we're only using one PendingIntent (ID = 0):
            //const int pendingIntentId = 0;
            //PendingIntent pendingIntent =
            //    PendingIntent.GetActivity(this, pendingIntentId, intent, PendingIntentFlags.OneShot);
            ISharedPreferences prefs = Android.Preferences.PreferenceManager.GetDefaultSharedPreferences(this);

            try
            {
                Location.owner = prefs.GetInt("owner", 0);
            }
            catch
            {
                Location.owner = 0;
            }

            builder = new NotificationCompat.Builder(this)
                      .SetSmallIcon(Resource.Drawable.ic_stat_directions_bike)//.setTicker(text).setWhen(time)
                      .SetContentTitle("Location Service is running")
                      .SetContentText("Location Service is running")
                      .SetAutoCancel(true)
                      .SetOngoing(false)
                      .SetContentIntent(PendingIntent.GetActivity(this, 0, new Intent(), 0));
            notification        = builder.Build();
            notificationManager = GetSystemService(Context.NotificationService) as NotificationManager;
            notificationID      = (int)NotificationFlags.AutoCancel;

            StartForeground(notificationID, notification);

            savedLocations         = new List <Location>();
            lastLocation           = new Location();
            lastLocation.Latitude  = 0;
            lastLocation.Longitude = 0;

            locator = Plugin.Geolocator.CrossGeolocator.Current;
            //TTS = Plugin.TextToSpeech.CrossTextToSpeech.Current;
            locator.DesiredAccuracy = 50;
            //locator.StartListeningAsync(12000, 0);
            System.TimeSpan updateFreq = new TimeSpan(300000);
            locator.StartListeningAsync(updateFreq, 0);


            locator.PositionChanged += Locator_PositionChanged;
            locator.PositionError   += Locator_PositionError;

            // _player = Android.Media.MediaPlayer.Create(this, Resource.Raw.Alarm);
            //TTS.Speak("service started");

            //binder = new LocationServiceBinder(this);
        }
コード例 #6
0
        //this needs to be asynchronous because awaititng in the main thread causes a deadlock
        //sets the camera on user position if available
        async Task InitAsync()
        {
            locator = CrossGeolocator.Current;

            try
            {
                var pos = await locator.GetPositionAsync();

                await map.MoveCamera(CameraUpdateFactory.NewPosition(new Xamarin.Forms.GoogleMaps.Position(pos.Latitude, pos.Longitude)));
            }
            catch { }
        }
コード例 #7
0
ファイル: MainPage.xaml.cs プロジェクト: foadmk/MapSample
        public MainPage()
        {
            InitializeComponent();

            ServicePointManager
            .ServerCertificateValidationCallback +=
                (sender, cert, chain, sslPolicyErrors) => true;

            locator = CrossGeolocator.Current;
            locator.StartListeningAsync(TimeSpan.FromSeconds(30), 10.0);
            locator.PositionChanged += (object sender, Plugin.Geolocator.Abstractions.PositionEventArgs e) => gps_position_changed(sender, e);

            map.IsEnabled = false;
        }
コード例 #8
0
ファイル: CustomMap.cs プロジェクト: gilaShany/DogCare
        async public Task <Nullable <Position> > GetCurrentPosition(Plugin.Geolocator.Abstractions.IGeolocator locator)
        {
            try
            {
                var geoPosition = await locator.GetPositionAsync(10000);

                Position currentSampledPosition = new Position(geoPosition.Latitude, geoPosition.Longitude);
                this.UpdateCurrentPosition(currentSampledPosition, Utils.Utils.KPHtoMPS(speedThresholdKMH));
                return(this.currentPosition);
            }
            catch
            {
                return(null);
            }
        }
コード例 #9
0
        public async Task GetLocationAsync()
        {
            try
            {
                Plugin.Geolocator.Abstractions.IGeolocator locator = CrossGeolocator.Current;
                locator.DesiredAccuracy = 50;
                Plugin.Geolocator.Abstractions.Position location = await locator.GetPositionAsync();

                Latitude  = location.Latitude;
                Longitude = location.Longitude;
            }
            catch (Exception ex)
            {
                ex.ToString();
            }
        }
コード例 #10
0
ファイル: LocationService.cs プロジェクト: quilkin/WhereIAm
        void StartService()
        {
            ISharedPreferences prefs = Android.Preferences.PreferenceManager.GetDefaultSharedPreferences(this);

            try
            {
                Location.owner    = prefs.GetInt("owner", 0);
                Location.username = prefs.GetString("user", "unknown");
            }
            catch
            {
                Location.owner = 0;
            }

            builder = new Notification.Builder(this)
                      .SetSmallIcon(Resource.Drawable.icon)//.setTicker(text).setWhen(time)
                      .SetContentTitle("Location Service is running")
                      .SetContentText("Location Service is running");
            //.SetContentIntent(pendingIntent);
            notification        = builder.Build();
            notificationManager = GetSystemService(Context.NotificationService) as NotificationManager;
            notificationID      = (int)NotificationFlags.ForegroundService;
            builder.SetAutoCancel(true);
            StartForeground(notificationID, notification);

            savedLocations         = new List <Location>();
            lastLocation           = new Location();
            lastLocation.Latitude  = 0;
            lastLocation.Longitude = 0;

            locator = Plugin.Geolocator.CrossGeolocator.Current;
            locator.DesiredAccuracy = 50;


            // TimeSpan updateFreq = new TimeSpan(TimeSpan.TicksPerMinute * 2);
            // locator.StartListeningAsync(updateFreq, 0);
#if TESTING
            locator.StartListeningAsync(30000, 0);
#else
            // get new location every 2 minutes
            locator.StartListeningAsync(120000, 0);
#endif

            locator.PositionChanged += Locator_PositionChanged;
            locator.PositionError   += Locator_PositionError;
        }
コード例 #11
0
        async private void InitMap(double speedThresholdKMH)
        {
            map.speedThresholdKMH = speedThresholdKMH;
            isListening           = false;
            hasGPS                  = false;
            isPeeClicked            = false;
            isPoopClicked           = false;
            locator                 = CrossGeolocator.Current;
            locator.DesiredAccuracy = locatorDesiredAccuracy;
            map.MoveToRegion(MapSpan.FromCenterAndRadius(new Position(31.771959, 34.87018), Distance.FromMiles(50)));
            distance.Text = "0";
            var nPosition = await map.GetCurrentPosition(locator);

            if (nPosition == null)
            {
                DisplayAlertGPS();
            }
            else
            {
                var position = (Position)nPosition;
                map.MoveToRegion(MapSpan.FromCenterAndRadius(new Position(position.Latitude, position.Longitude), distanceFromMapInMiles));
            }

            //dealing with GPS that was turned off and then start working
            TimeSpan t = new TimeSpan(0, 0, 1);

            Device.StartTimer(t, () => {
                if (locator.IsGeolocationEnabled == false)
                {
                    hasGPS = false;
                }
                else
                {
                    if (hasGPS == false && isListening == true)
                    {
                        Device.BeginInvokeOnMainThread(() => {
                            DisplayAlert("GPS", "Retriving GPS location", "OK");
                        });
                        locator.StartListeningAsync(100, 0.1);
                        locator.PositionChanged += Current_PositionChanged;
                    }
                    hasGPS = true;
                }
                return(true);
            });
        }
コード例 #12
0
        private void SetUpEventWidget()
        {
            TrackingButton.Text = "Start Location";

            TrackingButton.Clicked += async(sender, events) =>
            {
                if (TrackingButton.Text == "Start Location")
                {
                    // tracking

                    Geolocator = CrossGeolocator.Current;
                    Geolocator.DesiredAccuracy  = 100;
                    Geolocator.PositionChanged += (_sender, _event) =>
                    {
                        Console.WriteLine($"Position Status: {_event.Position.Timestamp}");
                        Console.WriteLine($"Position Latitude: {_event.Position.Latitude}");
                        Console.WriteLine($"Position Longitude: {_event.Position.Longitude}");

                        var currentLocation = new Position(_event.Position.Latitude, _event.Position.Longitude);
                        map.MoveToRegion(MapSpan.FromCenterAndRadius(currentLocation, Distance.FromMeters(200)));
                    };
                    await Geolocator.StartListeningAsync(TimeSpan.FromSeconds(5), 50);

                    Device.BeginInvokeOnMainThread(() => {
                        TrackingButton.Text = "Stop Location";
                    });
                }
                else
                {
                    bool result = await DisplayAlert("title", "message", "yes", "no");

                    if (result == true)
                    {
                        await Geolocator.StopListeningAsync();

                        Device.BeginInvokeOnMainThread(() => {
                            TrackingButton.Text = "Start Location";
                        });
                    }
                }
            };
        }
コード例 #13
0
        private async void MoveToMyLocation()
        {
            //Log.WriteLine($"MoveToMyLocation");

            Plugin.Geolocator.Abstractions.IGeolocator locator  = CrossGeolocator.Current;
            Plugin.Geolocator.Abstractions.Position    position = await GetCurrentPosition();

            customMap.MoveToRegion(MapSpan.FromCenterAndRadius(new Position(position.Latitude, position.Longitude), Distance.FromMiles(1)));
            //Debug.Write($"position = {position}");

            Position userPosition = new Position(position.Latitude, position.Longitude);

            customMap.OnMoveToMyLocation(userPosition);
            //if(!customMap.con IsGridCenterDefined)
            //{
            //	 customMap.GridCenter = userPosition;
            //}
            //customMap.DebugPosition = userPosition;
            //customMap.GridStepSize = CustomMap.MIN_GRID_STEP_SIZE; //set => it invokes (should) DrawGrid
        }
コード例 #14
0
ファイル: MapPage.xaml.cs プロジェクト: cmhg/Travel
        protected async override void OnAppearing()
        {
            base.OnAppearing();
            locator = CrossGeolocator.Current;
            locator.PositionChanged += Locator_PositionChanged;
            await locator.StartListeningAsync(TimeSpan.FromSeconds(0), 100);

            var position = await locator.GetPositionAsync();

            var center = new Xamarin.Forms.Maps.Position(position.Latitude, position.Longitude);
            var span   = new Xamarin.Forms.Maps.MapSpan(center, 1, 1);

            locationsMap.MoveToRegion(span);

            using (SQLiteConnection conn = new SQLiteConnection(App.DatabaseLocation))
            {
                conn.CreateTable <Post>();
                var posts = conn.Table <Post>().ToList();
                DisplayInMap(posts);
            }
        }