GPS & Wifi

markh2011

Member
Licensed User
Longtime User
Hi,
I am creating a program that records gps settings but inside some buildings we cant get a gps signal so i want use Abwifi library to get the data.
How do i tell the gps to stop searching and use the wifi. because at the moment it just keeps on trying to get a signal.
this the code that i am using but just cant figure out what to do.
Please point me in the right direction.
I understand that trying to use accuracy is probably not going to work. Would a timer work & if so can someone provide an example of the syntax required:sign0085:
B4X:
Sub GPS_LocationChanged (Loc As Location)
   Currentloc = Loc
   Longitude = Loc.Longitude
   Latitude = Loc.Latitude 
   count = count + 1
   
    If Loc.Accuracy <=100 Then
   Dim now As Long                  
   now = DateTime.now
   DateTime.DateFormat = "dd/MM/yyyy"   
   Dim edtdate, edttime, edtdatetime As String
   edtdate = DateTime.Date(now)
   edttime= DateTime.Time(now)   
   aa = edtdate
   bb = edttime
   edtdatetime = aa &"-"& bb
   c = edtdatetime   
   Dim lat, lon As Double
   lon = Currentloc.Longitude
   lat = Currentloc.Latitude
   Dim req As HttpRequest
   sendrequest = "http://thexspots.webege.com/netdb.php?action=addgps&lat="
   req.InitializeGet(sendrequest & lat & "&lon=" & lon &"&deviceID=" & deviceID & "&reddt="& c)
   httpC.Execute(req, 1)
    GPS1.Stop 
    End If
   
    If Loc.Accuracy >100 Then
   Dim now As Long                  
   now = DateTime.now
   DateTime.DateFormat = "dd/MM/yyyy"   
   Dim edtdate, edttime, edtdatetime As String
   edtdate = DateTime.Date(now)
   edttime= DateTime.Time(now)   
   aa = edtdate
   bb = edttime
   edtdatetime = aa &"-"& bb
   c = edtdatetime   
   Dim lat, lon As Double
   Dim ResLocation As ABFoundLocation
   myWifi.ABGetLocation("myWifi")
   lon = ResLocation.Longitude
   lat = ResLocation.Latitude
   Dim req As HttpRequest
   sendrequest = "http://thexspots.webege.com/netdb.php?action=addgps&lat="
   req.InitializeGet(sendrequest & lat & "&lon=" & lon &"&deviceID=" & deviceID & "&reddt="& c)
   httpC.Execute(req, 1)
    GPS1.Stop 
   End If
   
   If count >10 Then
    GPS1.Stop
   Return
    End If
    
    If count Mod 5 = 0 Then
    ToastMessageShow("Locating..." & count, True)
    End If
    
   GPS1.Stop 
End Sub
 

derez

Expert
Licensed User
Longtime User
Try to check the status by this
B4X:
Sub GPS_GpsStatus (Satellites As List)
If Satellites.IsInitialized Then 
     if Satellites.Size < 4 then  counter = counter + 1
else
     counter = counter + 1
end if
if counter > 10 then gps1.stop   ' number according to how much time you want to try with GPS
end sub
 
Last edited:
Upvote 0

markh2011

Member
Licensed User
Longtime User
Thanks for the advice. How do i incorporate this into the gps locationchanged sub? I have got myself confused in what to do to make this work.
 
Upvote 0

derez

Expert
Licensed User
Longtime User
This sub is in addition to the locationchanged sub.
If the GPS is getting enough satellites to set its position then locationchanged sub will be used and you can do what you need to.

If your counter exceeds the limit that you set (for decision that GPS is not getting the position) then , in addition to stoping the GPS, you should run another sub in which you'll do the tasks of getting the position from WiFi (the part you put under the Loc.accuracy > 100 in your code)

So, to sum it up - You decide by the status sub if GPS is doing the job or not. If it does - use it (put the code for valid GPS in the locationchanged sub.
If not valid - run another sub with the code for WIFI location.
If the location setting needs to be repeted - use a timer to run the wifi sub again and again after enabling the timer in the status sub.
 
Last edited:
Upvote 0
Top