Filip Laurentiu
Filip Laurentiu

Reputation: 938

System.UnauthorizedAccessException: 'Access is denied location UWP

I try to make a simple weather aplication but i get an exception. I have location activated. I try to run in emulator for phone, not working the exception

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;


namespace TryToMakeWeatherApp
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class MainPage : Page
    {
        public MainPage()
        {
            this.InitializeComponent();
        }

        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            var pos = await LocationManage.GetLocation(); //Here i'm geting the error
            var lat = pos.Coordinate.Latitude;
            var lon = pos.Coordinate.Longitude;


            var weather = WeatherMap.GetWeather(lat, lon).ToString();
            WeatherTxt.Text = weather;
        }
    }
}

This is code from MainPage. And this is the LocationManage class

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Devices.Geolocation;

namespace TryToMakeWeatherApp
{
    class LocationManage
    {
        public async static Task<Geoposition> GetLocation()
        {
            var accessStatus = await Geolocator.RequestAccessAsync();

            var geolocator = new Geolocator { DesiredAccuracyInMeters = 0 };

            var position = await geolocator.GetGeopositionAsync();

            return position;


        }
    }
}

Upvotes: 0

Views: 1728

Answers (1)

Dave Smits
Dave Smits

Reputation: 1889

in your package.manifest file have to turn on this capability too

Upvotes: 2

Related Questions