0

ユーザーの現在の場所を取得しようとしていますが、コードでエラーが表示されます...

// try get user location
Geolocator geo = new Windows.Devices.Geolocation.Geolocator();
geo.DesiredAccuracyInMeters = 10;
try {
    Geoposition position = await geo.GetGeopositionAsync();
} catch (Exception e) { }

私の問題は、コンパイラがエラーを表示することですawait geo.GetGeopositionAsync();

「await」演算子は、それを含むメソッドまたはラムダ式が「async」修飾子でマークされている場合にのみ使用できます。

しかし、私が見たところ、これはマイクロソフトが示したものと同じコードです

私はすでに VS12 と PC (VM ですが、まだ) を再起動していますが、エラーはまだここにあります...何が問題なのですか?

私もこれを試してみましたが、それでも同じエラーが発生します:

 Geoposition position = await geo.GetGeopositionAsync().asTask<Geoposition>();
4

1 に答える 1

3

メソッドを async でマークする必要があります。

void **async** themethod()
    {
    // try get user location
    Geolocator geo = new Windows.Devices.Geolocation.Geolocator();
    geo.DesiredAccuracyInMeters = 10;
    try {
        Geoposition position = await geo.GetGeopositionAsync();
    } catch (Exception e) { }
}
于 2013-04-15T01:11:53.853 に答える