Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It looks like the fix was to block it from using the first value and getting it from the second event instead:</p> <pre><code>bool gpsReady = false; void watcher_PositionChanged(object sender, GeoPositionChangedEventArgs&lt;GeoCoordinate&gt; e) { if (gpsReady) { latitude = e.Position.Location.Latitude.ToString("0.0000000000"); longitude = e.Position.Location.Longitude.ToString("0.0000000000"); locReady = true; } gpsReady = true; } </code></pre> <p>I'm still baffled about why I don't get more events or why it fires an incorrect value first, but the above code seems to be working.</p> <p>One note, for anyone else trying this, is that you might think getting the value in the StatusChanged event would work, like so:</p> <pre><code>case GeoPositionStatus.Ready: latitude = watcher.Position.Location.Latitude.ToString("0.0000000000"); longitude = watcher.Position.Location.Longitude.ToString("0.0000000000"); break; </code></pre> <p>I don't know why, but the above code seemed to work perfectly when I was running attached to the debugger and then frequently hung (that is, the event never fired and my UI seemed to hang) in practical use. I never managed to reproduced the issue while attached to the debugger.</p> <p>UPDATE: It looks like this isn't working all of the time. In some cases it doesn't fire the second time and so my code never completes running. If anyone can provide more information around this that gets me closer to simply having the actual current location of the device without fail, I will definitely mark your answer as the answer. Thanks! </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload