Geofencing documentation, tutorials or examples?

78 views
Skip to first unread message

Craig Lang

unread,
Jan 14, 2016, 1:25:57 PM1/14/16
to CodenameOne Discussions, cr...@craigrlang.com
Hi All,

I'm looking for documentation on how to use GeoFencing.
I saw references to it in the CodeNameOne Blog, but I haven't seen anything on how to actually use it.
I didn't see anything in the developer guide, and a google search turned up nothing that would instruct on how to use it.

I saw the GeoFenceListener class and associated methods in the LocationManager class listed in the JavaDocs
I've started to play with this, but I doubt I'm using it correctly. Haven't gotten it to actually work yet using the simulator.
Is there an example of an application using GeoFencing?

Thanx,
 Craig


Steve CN1 Hannah

unread,
Jan 14, 2016, 3:35:29 PM1/14/16
to codenameone...@googlegroups.com, cr...@craigrlang.com
Here is a simple example of using the GeofenceListener


--
You received this message because you are subscribed to the Google Groups "CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to codenameone-discu...@googlegroups.com.
Visit this group at https://groups.google.com/group/codenameone-discussions.
To view this discussion on the web visit https://groups.google.com/d/msgid/codenameone-discussions/7d6b0eb2-d788-4c45-a054-aa81099b9407%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Steve Hannah
Software Developer
Codename One

Craig Lang

unread,
Jan 15, 2016, 7:34:58 PM1/15/16
to CodenameOne Discussions, cr...@craigrlang.com

Thank you,
That helps quite a bit.

A couple of things that have me a little puzzled:
1) Unfortunately, for some reason, the listener is not being triggered. I never see the System.out.println output that would indicate that the onExit and onEnter are being called.
2) I noticed that when I used the @Override lines in the GeofenceListener class, the compiler complained.


Here is the code I used to implement the class so far. It should be the same thing as in the example, except that the @Override line isn't there.

Here is the GeofenceListener class
-----------------------------------------------
package userclasses;

import com.codename1.location.GeofenceListener;

public class GFListener implements GeofenceListener
{
    public void onExit(String id)
    {
        System.out.println("Exited "+id);
    }

    public void onEntered(String id)
    {
        System.out.println("Entered "+id);
    }
}


And here is the code that launches it:

    LocationManager lmg;
    void setBackgroundGPS()
    {
        lmg  = LocationManager.getLocationManager();
        Location baseLoc = getBaseLocation();
        System.out.println("Setting background location");
        System.out.println("Base location: " + baseLoc.getLatitude() + "/" + baseLoc.getLongitude());
        Geofence gf = new Geofence("GFTest", baseLoc, 500, 100000);
        lmg.addGeoFencing(GFListener.class, gf);
    }

    void clearBackgroundGPS()
    {
        if (lm != null )
        {
            lmg.removeGeoFencing("GFTest");
        }
    }
The resulting output on the console is:
Setting background location
Base location: 45.13945157305696/-93.27427055306242

So it appears that the correct latitude/longitude are being generated.
Not sure what I'm doing wrong. Any insights would be helpful.

Thanx,
 Craig

Craig Lang

unread,
Jan 15, 2016, 7:36:05 PM1/15/16
to CodenameOne Discussions, cr...@craigrlang.com
Also, how well does this work with the simulator?
I'm testing the geofencing using the simulator.

Steve Hannah

unread,
Jan 15, 2016, 7:38:11 PM1/15/16
to codenameone...@googlegroups.com, cr...@craigrlang.com
This hasn't been added to the simulator yet.  It is only on Android and iOS presently.  Please file an RFE in the issue tracker.

--
You received this message because you are subscribed to the Google Groups "CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to codenameone-discu...@googlegroups.com.
Visit this group at https://groups.google.com/group/codenameone-discussions.

For more options, visit https://groups.google.com/d/optout.



--
Steve Hannah
Web Lite Solutions Corp.
Reply all
Reply to author
Forward
0 new messages