Hello, can someone help me with my problem? I have app that show GPS position. I have timer so my data is updated every X seconds. This is OK. But problem is, that GPS is working non-stop. Therefore battery consumption is very big.
This is my code. I can not figure it out, how to correctly STOP GPS after getting latitude / longtitude and START it after X second again.
If I set locator.Interval - it does not work
If I set:
locator.Stop();
locator.Dispose();
locator = null;
my GPS position is located only once. After 60 second (or later) is not updated… Same position.
my code:
public void GetGPSPosition()
{
Device.StartTimer(TimeSpan.FromSeconds(1), () =>
{
_gps_seconds--;
if (_gps_seconds == 0)
{
GetActualGPS();
_gps_seconds = 60;
}
return _isTimerStart;
});
}
public void GetActualGPS()
{
try
{
Tizen.Location.Locator locator;
locator = new Locator(LocationType.Hybrid); // .Gps
locator.Start();
// locator.Interval = 60;
Tizen.Location.Location location = locator.GetLocation();
if (location != null)
{
gps_location_latitude = location.Latitude.ToString().Replace(",", ".");
gps_location_longtitude = location.Longitude.ToString().Replace(",", ".");
latitude.Text = String.Format("{0:F5}", gps_location_latitude);
longitude.Text = String.Format("{0:F5}", gps_location_longtitude);
}
else
{
DisplayAlert("0", "location is null", "OK");
}
//locator.Stop();
//locator.Dispose();
//locator = null;
}
catch (Exception ex)
{
DisplayAlert("Unable to get location", ex.Message, "OK");
}
}