コード例 #1
0
        private async Task GetUserLocationAsync()
        {
            var locationStatus = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Location);

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

                locationStatus = results[Permission.Location];
            }
            if (locationStatus == PermissionStatus.Granted)
            {
                var location = await Geolocation.GetLastKnownLocationAsync();

                if (location != null)
                {
                    ToMap.MoveToMapRegion(MapSpan.FromCenterAndRadius(
                                              new Position(location.Longitude, location.Longitude), Distance.FromKilometers(50)), true);
                }
            }
            else
            {
                await DisplayAlert(AppResources.PermissionsDenied, AppResources.PermissionLocationDetails,
                                   AppResources.Ok);

                //On iOS you may want to send your user to the settings screen.
                CrossPermissions.Current.OpenAppSettings();
            }
        }
コード例 #2
0
        async void ItemSelected(object sender, SelectedItemChangedEventArgs e)
        {
            if (e.SelectedItem == null)
            {
                return;
            }
            var prediction = (IPlaceResult)e.SelectedItem;

            try
            {
                var Address = prediction.Description;
                addlbl.Text        = Address;
                Settings.Placeto   = addlbl.Text;
                Orderbtn.IsVisible = true;
                var locations = await Geocoding.GetLocationsAsync(Address);

                var location = locations?.FirstOrDefault();
                if (location != null)
                {
                    Settings.Latto = location.Latitude.ToString();
                    Settings.Lngto = location.Longitude.ToString();
                    var newPin = new TKCustomMapPin
                    {
                        Position = new Position(location.Latitude, location.Longitude),
                        Title    = "Cluster Test",
                        Image    = "placeholder.png"
                    };
                    Pins.Clear();
                    Pins.Add(newPin);
                    ToMap.Pins = Pins;
                    ToMap.MoveToMapRegion(MapSpan.FromCenterAndRadius(
                                              new Position(location.Longitude, location.Longitude), Distance.FromKilometers(50)), true);
                    Orderbtn.IsVisible = true;
                }
            }
            catch (Exception ex)
            {
            }

            // HandleItemSelected(prediction);
        }