When I use the WinRT Geolocator, I sporadically get the error:
{"The pipe is being closed. (Exception from HRESULT: 0x800700E8)"}
Again, this is sporadic. Any suggestions?
Windows.Devices.Geolocation.Geoposition _Postion = null;
try
{
var _Locator = new Windows.Devices.Geolocation.Geolocator();
_Postion = await _Locator.GetGeopositionAsync();
}
catch { /* continue, null okay */ }
if (_Postion == null)
{
/* use alternate */
}
else
{
/* use location */
}
This is in the simulator, but also when run on local machine. Usually this error will NOT result in a break. It just ends the app suddenly. When it does result in a break. That is the resulting error.
I figured out that this happened when your localization is set as "simulated", if you are running your app using device simulator you may disable this by click in world icon (between display and camera settings), then uncheck "Use simulated location" option
I think the root cause for this issue is that GeoLocator is using Location API.
The error you are getting is HRESULT_FROM_WIN32(ERROR_NO_DATA), which seems to map to the friendly (but unhelpful, in this case) string "The pipe is being closed." That's the expected error when the platform doesn't see your sensor providing a valid report.
I also faced a similar sporadic exception in my project. Look at the image screenshot I attached.
Here is the solution which worked for me, but I am not sure whether it will work for others.
This was my code before:
Geolocator loc = new Geolocator();
try
{
loc.DesiredAccuracy = PositionAccuracy.High;
Geoposition pos = await loc.GetGeopositionAsync();
var lat = pos.Coordinate.Point.Position.Latitude;
var lang = pos.Coordinate.Point.Position.Longitude;
Status = loc.LocationStatus;
return GetGpsInfoObject(pos);
}
catch (System.UnauthorizedAccessException)
{
return null;
}
I changed the code to:
Geolocator loc = new Geolocator();
try
{
loc.DesiredAccuracy = PositionAccuracy.High;
Geoposition pos = await loc.GetGeopositionAsync();
var lat = pos.Coordinate.Point.Position.Latitude;
var lang = pos.Coordinate.Point.Position.Longitude;
Status = loc.LocationStatus;
return GetGpsInfoObject(pos);
}
catch (Exception)
{
return null;
}
User contributions licensed under CC BY-SA 3.0