Package com.codename1.location
package com.codename1.location
Abstraction of location services (GPS/Geofencing etc.) providing user global positioning and monitoring over such changes both in the foreground and background.
Trivial one time usage of location data can look like this sample:
Location position = LocationManager.getLocationManager().getCurrentLocationSync();
You can also track location in the foreground using API calls like this:
public MyListener implements LocationListener {
public void locationUpdated(Location location) {
// update UI etc.
}
public void providerStateChanged(int newState) {
// handle status changes/errors appropriately
}
}
LocationManager.getLocationManager().setLocationListener(new MyListener());
Geofencing allows tracking whether a user entered a specific region, this can work when the app is completely in the background and is very efficient in terms of battery life:
// File: GeofenceListenerImpl.java
public class GeofenceListenerImpl implements GeofenceListener {
@Override
public void onExit(String id) {
}
@Override
public void onEntered(String id) {
if(!Display.getInstance().isMinimized()) {
Display.getInstance().callSerially(() -> {
Dialog.show("Welcome", "Thanks for arriving", "OK", null);
});
} else {
LocalNotification ln = new LocalNotification();
ln.setId("LnMessage");
ln.setAlertTitle("Welcome");
ln.setAlertBody("Thanks for arriving!");
Display.getInstance().scheduleLocalNotification(ln, System.currentTimeMillis() + 10, LocalNotification.REPEAT_NONE);
}
}
}
// File: GeofenceSample.java
Geofence gf = new Geofence("test", loc, 100, 100000);
LocationManager.getLocationManager().addGeoFencing(GeofenceListenerImpl.class, gf);
-
ClassDescriptionMetadata for geofencing support that allows tracking user location in the background while the app is inactive.Listener interface for the Geofence background tracking functionality.A utility class to simplify Geofencing in Codename One.The Listener class that is registered to receive Geofence events.Represents a position and possible velocity returned from positioning API's.This is a Listener to the Locations events see LocationManager.setLocationListenerThe LocationManager is the main entry to retrieveLocation or to bind a LocationListener,This class is used when requesting to listen to location update.