Windows Phone - 持续跟踪和ReverseGeocodeQuery

时间:2013-03-01 19:56:35

标签: maps windows-phone-8 windows-phone

我正在使用新的Windows Phone 8 Maps和Maps Toolkit。在每个PositionChanged事件中,我将UserLocationMarker设置为新位置。如果用户点击UserLocationMarker,我会通过ReverseGeocodeQuery显示地图位置,并将用户位置图钉设置为可见。要快速执行此操作,请执行ReverseGeocodeQuery事件中的PositionChanged

我的问题是,如果用户位置变化非常快,它将执行许多ReverseGeocodeQuery s。这是性能问题吗?

private void InitializeGeolocator()
{
    geolocator = new Geolocator();
    geolocator.DesiredAccuracy = PositionAccuracy.High;
    geolocator.MovementThreshold = 5;
    geolocator.StatusChanged += geolocator_StatusChanged;
    geolocator.PositionChanged += geolocator_PositionChanged;
}

private void geolocator_PositionChanged(Geolocator sender, PositionChangedEventArgs args)
{
    Dispatcher.BeginInvoke(() =>
    {
        Geoposition geoposition = args.Position;

        this.UserLocationMarker.GeoCoordinate = geoposition.Coordinate.ToGeoCoordinate();
        this.UserLocationMarker.Visibility = System.Windows.Visibility.Visible;

        // execute ReverseGeocodeQuery...
        // set Pushpin
    });
}

private void userLocationMarker_tap(object sender, GestureEventArgs e)
{
    // show user location pushpin...
    UserLocationPushpin.Visibility = Visibility.Visible;
}

1 个答案:

答案 0 :(得分:1)

如果在ReverseGeocodeQuery事件中调用PositionChanged,则是,这可能会导致性能问题。

作为一般规则,Windows Phone(和Windows 8 / WinRT)中的任何异步调用通常意味着它可能不会在固定时间内返回值 - 可能需要50毫秒,可能需要5秒。

使用ReverseGeocodeQuery,它会拨打诺基亚服务器(geo.nlp.nokia.com)的网络电话来获取地址。虽然这种呼叫在使用Wifi或良好的3G连接时会很快恢复,但如果接收效果不佳则不会这样。

虽然我可以理解你要做的事情 - 提前查看地址,以便当用户点击UserLocationMarker时,地址立即出现 - 网络质量不佳可能会造成延迟或例外。

我的建议是遵循内置地图应用已经使用的方法。也就是说,当用户点击UserLocationMarker时,它会显示“Looking ...”标签,然后执行异步地址查找,然后使用该地址更新该标签。

另外请记住,我们不知道ReverseGeocodeQuery是否受速率限制。它似乎不是,但随着大多数其他服务的发展,这可能会改变 - such as Google’s Geocoding API

你决定做什么,方便的测试工具是......

  1. Fiddlerand how to use Fiddler with the WP8 emulator
  2. Simulation Dashboard for Windows Phone(模拟糟糕的网络状况等)