Control over GPS1.Start

myriaddev

Active Member
Licensed User
Longtime User
Hi. I have been trying to control how often
I get an update of a GPS Location using
GPS1.Start(5000, 0) using GPS example.
I still got new locations every 1 sec or so ?!
Help, Jerry
 

LittleEddie

Member
Licensed User
Longtime User
That's because you have the
MinimunDistance set to 0
if the gps error is 2 meters and changes to 3 meters you will get a event.
Make it
GPS1.Start(5000, 100)

which is, update every 5 seconds or if I move 100 meters.

Ed
 
Upvote 0

myriaddev

Active Member
Licensed User
Longtime User
Please try Start(5000, 100) ?!

Hi. I tried GPS1.Start(5000, 100) and got one Location
update in many mins. Maybe I am missing something?
The "Satellites" info did update quickly.
Help, Jerry
 
Upvote 0

LittleEddie

Member
Licensed User
Longtime User
As long as it's getting info it should update,

it is installed on a phone and outside? (good signal)

and you have something in LocationChanged to show you every time it's called

Ed
 
Upvote 0

myriaddev

Active Member
Licensed User
Longtime User
Please test code

Hi again. I have tested the code below (GPS example)
on my Galaxy Tab v2.2.1 and my xoom v3.0.1 outside
and inside my office with the same results.
GPS1.Start(5000,100) --- only one location update (BAD)
GPS1.Start(0,0) --- updates about every second

Please test code! Maybe I am missing something ?!
Help, Jerry




Sub Process_Globals
Dim GPS1 As GPS
End Sub

Sub Globals
Dim lblLon As Label
Dim lblLat As Label
Dim lblSpeed As Label
Dim lblSatellites As Label
Dim num As Int ' *** Added
End Sub

Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
GPS1.Initialize("GPS")
num = 0 ' *** Added
End If
Activity.LoadLayout("1")
End Sub

Sub Activity_Resume
If GPS1.GPSEnabled = False Then
ToastMessageShow("Please enable the GPS device.", True)
StartActivity(GPS1.LocationSettingsIntent) 'Will open the relevant settings screen.
Else
GPS1.Start(5000, 100) ' *** Changed - produces only one update over several mins
'GPS1.Start(0, 0) ' *** Changed - produces an update about every 1sec
End If
End Sub

Sub Activity_Pause (UserClosed As Boolean)
GPS1.Stop
End Sub

Sub GPS_LocationChanged (Location1 As Location)
lblLat.Text = "Lat = " & Location1.ConvertToMinutes(Location1.Latitude)
lblLon.Text = "Lon = " & Location1.ConvertToMinutes(Location1.Longitude)
num = num + 1 ' *** Added
lblSpeed.Text = "Changes = " & num ' *** Changed
Log("GPS_LocationChanged")
End Sub

Sub GPS_UserEnabled (Enabled As Boolean)
ToastMessageShow("GPS device enabled = " & Enabled, True)
End Sub

Sub GPS_GpsStatus (Satellites As List)
lblSatellites.Text = "Satellites:" & CRLF
For i = 0 To Satellites.Size - 1
Dim Satellite As GPSSatellite
Satellite = Satellites.Get(i)
lblSatellites.Text = lblSatellites.Text & CRLF & Satellite.Prn & _
" " & Satellite.Snr & " " & Satellite.UsedInFix & " " & Satellite.Azimuth _
& " " & Satellite.Elevation
Next
End Sub
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
I think MinimumDistance overrides MinimumTime. From the requestLocationUpdates method here LocationManager | Android Developers - my boldening
The frequency of notification may be controlled using the minTime and minDistance parameters. If minTime is greater than 0, the LocationManager could potentially rest for minTime milliseconds between location updates to conserve power. If minDistance is greater than 0, a location will only be broadcasted if the device moves by minDistance meters. To obtain notifications as frequently as possible, set both parameters to 0.
...
minTime the minimum time interval for notifications, in milliseconds. This field is only used as a hint to conserve power, and actual time between location updates may be greater or lesser than this value.

minDistance the minimum distance interval for notifications, in meters
 
Upvote 0

myriaddev

Active Member
Licensed User
Longtime User
Thanks for the Help!

"I think MinimumDistance overrides MinimumTime." by
agraham. I agree. Thank you for a fast answer agraham!
Here are my measurements:

GPS1.Start(5000,100) --- only one location update (BAD)
GPS1.Start(0,0) --- updates about every second
GPS1.Start(5000,0) --- updates about every second (BAD)

I have moved the GPS activity code to a service, and will
turn off GPS in side service routine after getting a Location
and then call the service routine when I need a new
Location again from Main ?!

Thanks again ED, and agraham,
Jerry
 
Upvote 0
Top