【问题标题】:Error when trying to get my current location using Bing Maps in a Windows Store App尝试在 Windows 应用商店应用中使用 Bing 地图获取我的当前位置时出错
【发布时间】:2013-11-11 01:00:58
【问题描述】:

我正在开发一个使用 Bing 地图控件的 Windows 应用商店应用程序。我创建了一个使用 GeolocatorGeoPosition 来获取用户当前位置的方法。

另外,我从清单文件中启用了定位功能

但是,每次运行应用程序时,我第一次单击按钮获取位置时,都会收到以下错误消息:访问被拒绝。 (来自 HRESULT 的异常:0x80070005 (E_ACCESSDENIED))

当我第二次单击同一个按钮以执行相同的操作时,现在错误消息消失了,Bing 地图可以正常工作,向我显示我当前的位置。但是,我有点担心为什么我第一次尝试获取位置时总是收到错误消息。

这是我执行的两种获取位置的方法:

private async Task SetMyLocation()
{
    var position = await GetCurrentPosition();
    if (position != null)
    {
        this.DataContext = position;

        this.myLocation = new Location(position.Latitude, position.Longitude);
        this.myMap.Center = this.myLocation;
        //this.myMap.ZoomLevel = 20;
        this.myMap.SetView(myLocation, 12, MapAnimationDuration.Default);

        this.AddMyLocationPushpin();
    }
}

private async Task<Position> GetCurrentPosition()
{
    try
    {
        Geolocator geolocator = new Geolocator();
        geolocator.DesiredAccuracy = PositionAccuracy.High;
        geolocator.MovementThreshold = 0;

        Geoposition location = await geolocator.GetGeopositionAsync(
            maximumAge: TimeSpan.FromMinutes(5),
            timeout: TimeSpan.FromSeconds(10)
            );

        var postion = new Position
        {
            Latitude = location.Coordinate.Latitude,
            Longitude = location.Coordinate.Longitude
        };

        return postion;
    }
    catch (Exception ex)
    {
          . . .
          return null;
    }
}

任何建议,评论为什么我收到上述错误消息?任何线索和/或解决方案都可以吗?

问候!

【问题讨论】:

  • 从哪一行抛出异常?

标签: c# windows-store-apps bing-maps


【解决方案1】:

确保您已允许您的应用访问用户位置。打开包清单并转到功能选项卡。确保选中位置选项。重新运行您的应用程序,系统会提示您允许该应用程序访问您的位置,允许它。然后它应该为你工作。您可以在此处找到有关此的博客文章示例:http://www.bing.com/blogs/site_blogs/b/maps/archive/2012/11/05/getting-started-with-bing-maps-windows-store-apps-native.aspx

【讨论】:

  • 我面临同样的情况,如果我允许获取位置的权限,然后假设我关闭位置设置,下一次,它不会请求许可,我也没有得到任何异常那个案子。我想要做的是当位置设置关闭时,我想让我的用户打开位置设置。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-06-25
  • 1970-01-01
  • 1970-01-01
  • 2016-03-31
  • 1970-01-01
  • 2023-03-29
  • 2015-02-28
相关资源
最近更新 更多