1
votes

I'm using the new Windows Phone 8 Maps and the Maps Toolkit. On each PositionChanged event, I set the UserLocationMarker to the new position. If the user taps on the UserLocationMarker, I will show the map location via ReverseGeocodeQuery and set the user location Pushpin to visible. To do this really fast, I execute the ReverseGeocodeQuery in the PositionChanged event.

My question is, if the users location changed very quickly, it will execute many ReverseGeocodeQuerys. Is this a performance issue?

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

1 Answers

1
votes

If ReverseGeocodeQuery is called inside the PositionChanged event, then yes, this can lead to performance problems.

As a general rule, any asynchronous call in Windows Phone (and Windows 8 / WinRT) usually implies that it may not return a value in a fixed time - it may take 50ms, it may take 5 seconds.

With ReverseGeocodeQuery, it makes a network call to Nokia’s servers (geo.nlp.nokia.com) to get the address. And although this call return very quickly when using Wifi or a good 3G connection, this would not be true if you had poor reception.

And although I can understand what you’re trying to do - look up the address in advance so that when a user taps on the UserLocationMarker, the address appears instantly - bad network quality could create either a delay or an exception.

My suggestion would be to follow the approach that the built-in Maps app already uses. That is, when a user taps on the UserLocationMarker, it displays a “Looking...” label, then does an async address lookup, then updates that label with the address.

Also keep in mind, we don’t know if ReverseGeocodeQuery is rate limited. It doesn’t appear to be, but that might change in future as most other services are - such as Google’s Geocoding API.

What ever you decide to do, handy tools for testing are...

  1. Fiddler (and how to use Fiddler with the WP8 emulator)
  2. Simulation Dashboard for Windows Phone (simulate bad network conditions, etc)