Android Tutorial Geofence - Monitoring a region in the background

Discussion in 'Tutorials & Examples' started by Erel, Oct 8, 2017.

  1. Beja

    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.
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    The three formats are supported. The code from the example uses the first format.
     
    Beja likes this.
  3. Beja

    Beja Expert Licensed User

    Thanks Erel
     
  4. Beja

    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
     
  5. Erel

    Erel Administrator Staff Member Licensed User

    You will need to check the logs and find the error message.
     
  6. DonManfred

    DonManfred Expert Licensed User

    check the unfiltered logs also
     
  7. Beja

    Beja Expert Licensed User

    Ok Don, sorry was looking to the wrong place.
     
  8. Christian García S.

    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: Dec 12, 2017
  9. DonManfred

    DonManfred Expert Licensed User

    The event which raise contains the ID of the Fence you entered....
    It is the ID you set when creating the Fence.

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

    Public Sub Geofence_Exit (Id As String)
       
    Log("Exit: " & Id)
    End Sub
     
    jimmyF and Erel like this.
  10. BillMeyer

    BillMeyer Active 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.
     
  11. Erel

    Erel Administrator Staff Member Licensed User

    You can add this sub to the GeofenceService:
    Code:
    Public Sub RemoveGeofence(geo As Geofence)
     
    Dim g As List
     g.Initialize
     g.Add(geo.Id)
     client.RunMethod(
    "removeGeofences"Array(g))
    End Sub
     
  12. themr23

    themr23 Member Licensed User

    I tried this sample project on a specific device, where adding a fence always gave back 'false'.
    Logs said
    Code:
    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.
    Code:
    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: Dec 31, 2018
  13. Erel

    Erel Administrator Staff Member Licensed User

    I've updated the example with targetSdkVersion set to 26. Please try it.
     
    jimmyF likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice