Android Tutorial Geofence - Monitoring a region in the background

Beja

Expert
Licensed User
I found a workaround, that one can define a series of overlapped circular fences with radius of .5 * the desired rectangular width.. The number if fences corresponds to the desired resolution of the rectangle.
 

Beja

Expert
Licensed User
Hi Erel,
Today I tried to run the example and on one phone it just closed without notification, and on another one it said "Unfortunately, B4A Example has stopped. Open app again"
any help appreciated.
Using B4A 7.01
 

Christian García S.

Active Member
Licensed User
Hello, It have been implented this library in a marketing project and works perfect, but I need this library for a logistic project.

I have a question, the event Geofence is launched one time when the user enter to the geofence.

There are a way for asking which is geofence I am inside, is for validation porpuses, I know I can make a variable and save this information.

For example if the app is closed or the phone is restarted and I receive the notification, I can not use this variable for some validation, because the event is only triggered one time.

Or can you give me an idea how I can validate location??

Thanks for your help.

Regards,
Christian
 
Last edited:

DonManfred

Expert
Licensed User
There are a way for asking which is geofence I am inside
The event which raise contains the ID of the Fence you entered....
It is the ID you set when creating the Fence.

B4X:
   Dim geo As Geofence
   geo.Initialize
   geo.Id = "Test1" ' ID is here....
   geo.Center.Initialize2(32.8372, 35.2698) 'change location!
   geo.RadiusMeters = 100
   geo.ExpirationMs = DateTime.TicksPerDay 'expire after one day
B4X:
Public Sub Geofence_Enter (Id As String)
   Log("Enter: " & Id)
End Sub

Public Sub Geofence_Exit (Id As String)
   Log("Exit: " & Id)
End Sub
 

BillMeyer

Well-Known Member
Licensed User
Good Day,

I have a situation where I place a GeoFence at an Accident Scene. The time that it takes for the Accident to be cleared up is variable. After the clean up I no longer need the GeoFence and need to expire it.

Will it suffice to re-write/over write the fence and then just alter the ExpirationsMs to DateTime.Now ? or is there another way of doing this ?

If I need to create a new thread, I will, please advise.
 

themr23

Member
Licensed User
I tried this sample project on a specific device, where adding a fence always gave back 'false'.
Logs said
B4X:
Ignoring addGeofence because network location is disabled.
Geofence added: false
Phone reports location services available of: network,gps
Fine location Permission successful: permission android.permission.ACCESS_FINE_LOCATION result true

Update: Turns out that specific device had a 'Google account / phone number issue*'. A second identical device had no problem with this sample, and neither did a different device.

Digging into the full logs, I had found this message, which I assume is hint.
B4X:
Active mobile network without subscriber!
Context:
B4A 8.3
jdk1.8.0_171
C:\android\platforms\android-27\android.jar

Erel/B4X: you can delete this message if of no further value.

* the observed issue is the device with a SIM card was reporting a different phone number, which had been on the (removed 2nd) SIM from the identical 2nd phone. When I started using that phone, I didn't factory reset it, and just registered my account. After that my (first) phone started displaying the second phone's old number on the lock screen below the time/date. Until this GeoFence test and finding that log entry, there has been no other known issue on the first phone due to having that incorrect number displayed. Someday I might reset it, as no other steps have corrected it so far.
 
Last edited:
Top