none
A better way to call an async method RRS feed

  • Question

  • Hi, I'm using the snippet bellow to get my current position and then to use the coordinates to make an async call to the bing api for reverse geocoding.

    _cts = new CancellationTokenSource();
                    CancellationToken token = _cts.Token;
    
                    Geoposition position = await _geolocator.GetGeopositionAsync().AsTask(token);
    
                    longtitude = position.Coordinate.Point.Position.Longitude;
                    latitude = position.Coordinate.Point.Position.Latitude;    
    
    while (longtitude==0 && latitude==0)
    				{
    					await Task.Delay(100);
    				}
                    if (longtitude != 0 && latitude != 0)
                    {
                        string coordinates = latitude.ToString() + "," + longtitude.ToString();
                        Uri geocodeRequest = new Uri(string.Format("http://dev.virtualearth.net/REST/v1/Locations/{0}?&incl=ciso2&key={1}", coordinates, BingKey));            
    The reason I'm using the while loop is because some times the longitude and latitude have still zero value when the Bing api is called, but I'm sure there must be a better way to wait first for the two variables to be populated and then call the async method. Can anybody help. Thanks in advance.

    Thursday, November 5, 2015 8:00 PM

Answers

  • What about waiting for the change to occur?

    https://msdn.microsoft.com/en-us/library/windows/apps/windows.devices.geolocation.geolocator.aspx#events


    http://pauliom.wordpress.com

    Thursday, November 5, 2015 8:42 PM