Android Question GPS start parameters

dibesw

Active Member
Licensed User
Longtime User
I did not understand about the parameters of gps start.
B4X:
GPS1.Start(0, 100)
mean that if I am within 100 meters does not give me the coordinates?
 

Mark Read

Well-Known Member
Licensed User
Longtime User
The 0 is the speed to aquire a fix, 0 means as quick as possible. The 100 means don't update the position if it is within 100 meters of the last position.

Hope I got that right.
 
Upvote 0

jsanchezc

Member
Licensed User
Longtime User
First parameter is minimum time in milliseconds, second is minum distance in meters.
GPS1.Start(1000,100)
take lat/long each 1000ms or each 100 meters
if you are within 100 meters of the last position, you'll have a lat/long each 1000ms
if you move 100 meters before 1000ms the you also will have a lat/long.

GPS1.Start(0,100)
If you don't move you will not get lat/long.

To start test GPS i think is better begin with something like GPS1.Start(100,5)
Once your code works you can test other parameters to save battery.

If you don't have battery problems, best is GPS1.Start(0,0)
 
Upvote 0

dibesw

Active Member
Licensed User
Longtime User
Thank you, but my case is:
B4X:
Sub GPS_LocationChanged (Loc As Location)

  Currentloc = Loc
  count = count + 1
  Longitude = Loc.Longitude
  Latitude = Loc.Latitude
  colon = stri.Mid(Longitude,1,8)
  colat = stri.Mid(Latitude,1,8)
  '  orex<>DateTime.GetHour(DateTime.Now) AND minx<>DateTime.GetMinute(DateTime.Now)
  If colon <> lat1 AND colat <> lon1 Then
    createRecord
  End If
  GPS1.Stop
End Sub
Sub Service_Start (StartingIntent As Intent)
  StartServiceAt("", DateTime.Now + 1 * DateTime.TicksPerMinute, False)
  GPS1.Start(0, 100)
End Sub
I have a ServiceStartAt because the service must to start every 1 minute.
I have need not take lat/lon if I not move.
However in this case I take lat/long always (every 1 minues).
So in GPS_LocationChanged sub I was forced to test first 8 char of every lat/lon that takes.
How can I do better?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
This parameter is not relevant for your program as you are only listening to the first event.

Also note that it is only a hint to the system. You cannot rely on it if the distance is important for you. Instead use the Geodesic class to calculate the distance.

Note that there is a bug in your code. You should not call GPS.Start multiple times without stopping the GPS (as will happen if it takes longer than one minute to get a fix).
 
Upvote 0

dibesw

Active Member
Licensed User
Longtime User
Thanks Erel, but how do I know if I do not have GPS signal?
There isn't any event that tell me so.
If Locationchanged not run, how can I do?
 
Upvote 0

dibesw

Active Member
Licensed User
Longtime User
Yes, I understand, then the question is:
if I haven't location GPS don't stop, then how do I stop the gps?
You said before "Start multiple times without stopping"
 
Upvote 0
Top