In my Windows Phone 8 app, I am trying to use GetGeopositionAsync on the main page to display some items based on user location.
Calling GetGeopositionAsync does not
Well it looks like everyone hacked away until it worked... Here's what worked for me:
///
/// HACK: For some reason Geolocator.GetGeopositionAsync hangs indefinitely.
/// The workaround is to add a PositionChanged handler.
///
private Geoposition GetGeoposition()
{
var geolocator = new Geolocator();
var semaphoreHeldUntilPositionReady = new SemaphoreSlim(initialCount: 0);
Geoposition position = null;
geolocator.ReportInterval = 1000;
geolocator.PositionChanged += (sender, args) =>
{
position = args.Position;
semaphoreHeldUntilPositionReady.Release();
};
semaphoreHeldUntilPositionReady.Wait();
return position;
}