gps question

khos

Member
Licensed User
Longtime User
Hi all,

I have been looking at the GPS functions, added the library and looked at the demo on http://www.b4x.com/forum/basic4android-getting-started-tutorials/6592-gps-tutorial.html#post38535 , that is ok, my question is how can I invoke the gps to provide location details upon a button click event?

so similar to:
Sub GPS_LocationChanged (Location1 As Location)
lblLat.Text = "Lat = " & Location1.ConvertToMinutes(Location1.Latitude)
lblLon.Text = "Lon = " & Location1.ConvertToMinutes(Location1.Longitude)
lblSpeed.Text = "Speed = " & Location1.Speed
End Sub

how can I do this for a button click event, I'd like to be able to get current longitude/latitude values whenever I need to..

when the gps starts. e.g.:

Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
GPS1.Initialize("GPS")
End If
Activity.LoadLayout("1")
End Sub

so when initilizing , then the longitude/latitude values are 0, so I would need to move to get some values/data before I can query these in my button click event?

Any help / advise would be most kind.

Kim
 

klaus

Expert
Licensed User
Longtime User
In Android you cannot call the GPS directly to get the last GPS fix (location).
The only way to get a fix is in the GPS_LocationChanged event routine.
What you could do is to start the GPS with GPS_Start(0,0) in the Button_Click event and stop it in GPS_LocationChanged when you got the location. This would avoid to run the GPS constantly, but you could have a certain delay before getting the fix.

Best regards.
 
Upvote 0
Top