0
デバイスの場所を取得するために使用するコードがあります。これは、monogame windows uwpプロジェクトで行われます。以前は次のコードが働いていました(私はVS2015 Communityにいました)。最近私は新鮮なOSを実行し、VS2017コミュニティをインストールしました。ついに私のプロジェクトを構築して実行しました。動作していないのは、Geolocator.RequestAccessAsyncが「予期しない時刻に呼び出されたメソッド」の例外をスローしていることだけです。何か案は?Geolocator.RequestAccessAsyncは「予期しない時刻に呼び出されたメソッド」例外をスローする
public async Task<Vector2> GetDeviceGps()
{
var accessStatus = await Geolocator.RequestAccessAsync();
switch (accessStatus)
{
case GeolocationAccessStatus.Allowed:
// If DesiredAccuracy or DesiredAccuracyInMeters are not set (or value is 0), DesiredAccuracy.Default is used.
Geolocator geolocator = new Geolocator { DesiredAccuracyInMeters = 10 };
// Subscribe to the StatusChanged event to get updates of location status changes.
//geolocator.StatusChanged += OnStatusChanged;
// Carry out the operation.
Geoposition pos = await geolocator.GetGeopositionAsync();
return new Vector2((float)pos.Coordinate.Point.Position.Longitude, (float)pos.Coordinate.Point.Position.Latitude);
case GeolocationAccessStatus.Denied:
//Do something!
break;
case GeolocationAccessStatus.Unspecified:
//Murp
break;
}
return Vector2.Zero;
}
これは、呼び出されたので、(ゲームのupdateメソッドから呼び出された)のように扱われている:あなたはあなたのアプリケーションで初めてRequestAccessAsyncを実行すると
mapper.GetDeviceGps().ContinueWith(pos =>
{
Vector2 bob = pos.Result;
});
これは技術的には解答ですが、「このコードはなぜ以前には動作しましたか」という質問には答えません。おそらくモノゲーム3.5と3.6の間で考えました。私はそれについてのいかなる証拠も見ない。モノゴームで作業するジオロケーションを取得しようとしている人には、ゲームをホストするXAMLページ(GamePage.xaml.cs - UIスレッド)で開始する必要がありました。これはおそらく、アクセス状況の変更もそこで処理する必要があるかもしれないことを意味します。不便! – Mokgra