UWP Geolocating服务一直告诉我,我在Seatlle

时间:2015-12-18 21:44:11

标签: c# uwp

我遇到地理位置问题。 Bing Maps不断向我展示我在西雅图(实际上我在波兰华沙)。我不知道这有什么不对。我已经在我的笔记本电脑(Win 10)和Windows Phone模拟器中启用了位置服务。地图加载很好,当我点击"找到我按钮" (appBarButton_Click方法)它将我的地图集中到西雅图。

private async void getLocation()
{
    Geolocator gl = new Geolocator
    {
        DesiredAccuracy = PositionAccuracy.High
    };
    Geoposition pos = await gl.GetGeopositionAsync();
    Geopoint myLocation = pos.Coordinate.Point;
    MyMap.Center = myLocation;
    MyMap.ZoomLevel = 12;
}

private void appBarButton_Click(object sender, RoutedEventArgs e)
{
    getLocation();
}

1 个答案:

答案 0 :(得分:0)

这是适用于我的代码。我首先检查了应用清单中的“位置”功能。

var accessStatus = await Geolocator.RequestAccessAsync();
if (accessStatus == GeolocationAccessStatus.Allowed)
{
    var geolocator = new Geolocator { DesiredAccuracyInMeters = 10 };
    var pos = await geolocator.GetGeopositionAsync();
    var myLocation = pos.Coordinate.Point;
    MyMap.MapServiceToken = "MyKey"; //Replace with your key
    MyMap.Center = myLocation;
    MyMap.ZoomLevel = 12;
};