Windows 8中的位置

时间:2012-10-31 15:08:14

标签: c# windows-8

我正在尝试在Windows 8中创建一个可以找到用户位置的应用程序。为此,我有以下课程

public sealed partial class Cercano : CentrosCo.Common.LayoutAwarePage
{
    Geolocator geo = null;
    public Cercano()
    {
        this.InitializeComponent();
    }

    public async void button1_Click(
        object sender, RoutedEventArgs e)
    {
        if (geo == null)
        {
            geo = new Geolocator();
        }

        IGeoposition pos = await geo.GetGeopositionAsync();
        textLatitude.Text = "Latitude: " + pos.Coordinate.Latitude.ToString();
        textLongitude.Text = "Longitude: " + pos.Coordinate.Longitude.ToString();
        textAccuracy.Text = "Accuracy: " + pos.Coordinate.Accuracy.ToString();
    }

在IGeoposition中获取错误:

  

Windows.Devices.Geolocation.IGeoposition由于其保护级别而无法访问,

选择宣言中已有的位置......

1 个答案:

答案 0 :(得分:1)

Geolocator.GetGeopositionAsync() Method的异步返回类型为Geoposition,而不是 IGeoposition

试试这个:

Geoposition pos = await geo.GetGeopositionAsync();