System.UnauthorizedAccessException:'访问被拒绝的位置UWP

时间:2017-01-29 20:23:11

标签: c# uwp

我尝试制作一个简单的天气应用,但我得到了一个例外。 我已激活位置。我尝试在模拟器中运行手机,而不是工作 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;
        }
    }
}

这是MainPage的代码。 这是LocationManage类

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;


        }
    }
}

1 个答案:

答案 0 :(得分:2)

你的package.manifest文件中的

也必须打开这个功能