I'm trying to develop an application that should be something like a game. The user would have some locations in a city and he would have to do something on each location. In order to track the position of the user, I have tried using geolocation with the following code:
Geolocator geolocator = new Geolocator();
//geolocator.DesiredAccuracy = Windows.Devices.Geolocation.PositionAccuracy.High;
geolocator.DesiredAccuracyInMeters = 50;
try
{
Geoposition geoposition = await geolocator.GetGeopositionAsync(TimeSpan.FromMilliseconds(500), TimeSpan.FromSeconds(1));
textLatitude.Text = "Latitude: " + geoposition.Coordinate.Latitude.ToString("0.0000000000");
textLongitude.Text = "Longitude: " + geoposition.Coordinate.Longitude.ToString("0.0000000000");
textAccuracy.Text = "Accuracy: " + geoposition.Coordinate.Accuracy.ToString("0.0000000000");
}
Using the following way to get the coordinates I tried to test if the device will locate my position correctly with the following code:
if( Math.Abs(geoposition.Coordinate.Latitude - 45.3285) < 0.001 ){
if (Math.Abs(geoposition.Coordinate.Longitude - 14.4474) < 0.001)
{
txt.Text = "KONT";
}
}
The problem is that the accuracy of the location is really small, if I try using more precise coordinates it would never get the same coordinates again, and with this code the accuracy is really bad (it can fail even 300 meters).
Has anyone an idea how to get a more reliable location, or another way to fix that?
I think that the problem occurs, because you give too little time for Geolocator to make a proper readout with Geolocator.GetGeopositionAsync - timeout:
You give it only 1 second, while getting more accurate position takes time.
My example:
The code above returs a position (in my case) with accuracy of ~35 meters, BUT after waiting about 20-30 seconds. Note also that accuracy depends on numer of available sattelites.
Also some remarks from MSDN:
set Geolocator.ReportInterval to 0:
set Geolocator.DesiredAccuracyInMeters to 10 meters:
try to dealy between starting Geolocator and reding it:
try this:
At least for me the code is working ok, And I get to "txt.Text = "KONT" Where are you finding you constant latitude or longitude?