0
私は単純な天気のアプリケーションを作成しようとするが、私は例外が発生します。 私は場所が有効になっています。私は携帯電話用のエミュレータで実行しようと、これはメインページからのコードです the exceptionSystem.UnauthorizedAccessException: 'アクセスは拒否されました場所はUWP
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;
}
}
}
を働いていません。 そして、これはあなたのpackage.manifestファイルで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;
}
}
}
https://msdn.microsoft.com/en-us/windows/uwp/maps-場所と場所の取得 [設定]からアプリのアクセスを手動で許可してみましたか? –
私のアプリはpermisionを与えるためにリストに表示されません。 –
また、ユーザーが許可を拒否してテストすることを忘れないでください。 –