net.rim.device.api.location
Class Geofence

java.lang.Object
  extended by net.rim.device.api.location.Geofence

public class Geofence
extends Object

Provides methods that allow you to define geofenced areas and receive notifications when a BlackBerry device user enters or leaves the specified area.

A geofence is a virtual geographic area of interest that you can define by a radius around a location, or by coordinates that define a polygon for the location.

Applications must instantiate a Geofence object and implement the GeofenceListener to receive notifications for geofencing events (when a user enters or exits geofenced areas). Each instance of Geofence can process up to 20 monitored areas concurrently.

Since:
BlackBerry API 7.0.0

Field Summary
static int API_ACCESS_DENIED
          Indicates denied access to the API.
static int DUPLICATE_COORDINATES
          Indicates duplicate coordinates.
static int DUPLICATE_TAG
          Indicates a duplicate tag was specified.
static int INVALID_NUMBER_OF_COORDINATES
          Indicates an invalid number of coordinates.
static int INVALID_PARAMETERS
          Indicates the specified parameters are invalid.
static int INVALID_TAG
          Indicates an invalid tag was specified.
static int LOCATION_ACCURACY_HIGH
          Indicates the location accuracy level is high.
static int LOCATION_ACCURACY_LOW
          Indicates the location accuracy level is low.
static int LOCATION_ACCURACY_MEDIUM
          Indicates the location accuracy level is medium.
static int LOCATION_DISALLOWED_BY_IT_POLICY
          Indicates location services are disallowed by an IT policy.
static int LOCATION_DISALLOWED_BY_USER
          Indicates location services are disallowed by the user.
static int LOW_BATTERY
          Indicates current device battery level is low.
static int MAX_NUMBER_OF_MONITORED_AREAS
          Indicates the maximum number of areas to monitor.
static int NO_ERROR
          Indicates no error.
static int NUMBER_OF_MONITORED_AREAS_EXCEEDED
          Indicates the number of monitored areas is exceeded.
static int OTHER_FAILURE
          Indicates other possible failure.
static int OUT_OF_SERVICE
          Indicates current device location is unavailable.
static int SUCCESS
          Indicates success.
static int TEMPORARILY_UNAVAILABLE_AUTO_RESTART
          Indicates current device location is temporarily unavailable.
 
Constructor Summary
Geofence()
          Constructs a new Geofence instance.
 
Method Summary
 boolean isInPerimeter(String tag)
          Indicates whether the device is on or inside the perimeter of the monitored area.
 int monitorPerimeter(GeofenceListener listener, String tag, Coordinates coordinates, int radius, int accuracyFactor, int duration)
          Defines and monitors a circular perimeter for a location of interest during a specified time period.
 int monitorPerimeter(GeofenceListener listener, String tag, Coordinates[] coordinates, int accuracyFactor, int duration)
          Defines and monitors the perimeter for a polygon area during a specified time period.
 int removePerimeter(String tag)
          Stops monitoring a specified area.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 



Field Detail

MAX_NUMBER_OF_MONITORED_AREAS

public static final int MAX_NUMBER_OF_MONITORED_AREAS
Indicates the maximum number of areas to monitor.

See Also:
Constant Field Values
Since:
BlackBerry API 7.0.0

SUCCESS

public static final int SUCCESS
Indicates success.

See Also:
Constant Field Values
Since:
BlackBerry API 7.0.0

INVALID_PARAMETERS

public static final int INVALID_PARAMETERS
Indicates the specified parameters are invalid.

See Also:
Constant Field Values
Since:
BlackBerry API 7.0.0

INVALID_NUMBER_OF_COORDINATES

public static final int INVALID_NUMBER_OF_COORDINATES
Indicates an invalid number of coordinates.

See Also:
Constant Field Values
Since:
BlackBerry API 7.0.0

DUPLICATE_COORDINATES

public static final int DUPLICATE_COORDINATES
Indicates duplicate coordinates.

See Also:
Constant Field Values
Since:
BlackBerry API 7.0.0

INVALID_TAG

public static final int INVALID_TAG
Indicates an invalid tag was specified.

See Also:
Constant Field Values
Since:
BlackBerry API 7.0.0

DUPLICATE_TAG

public static final int DUPLICATE_TAG
Indicates a duplicate tag was specified.

See Also:
Constant Field Values
Since:
BlackBerry API 7.0.0

NUMBER_OF_MONITORED_AREAS_EXCEEDED

public static final int NUMBER_OF_MONITORED_AREAS_EXCEEDED
Indicates the number of monitored areas is exceeded.

See Also:
Constant Field Values
Since:
BlackBerry API 7.0.0

API_ACCESS_DENIED

public static final int API_ACCESS_DENIED
Indicates denied access to the API.

See Also:
Constant Field Values
Since:
BlackBerry API 7.0.0

OTHER_FAILURE

public static final int OTHER_FAILURE
Indicates other possible failure.

See Also:
Constant Field Values
Since:
BlackBerry API 7.0.0

LOCATION_ACCURACY_HIGH

public static final int LOCATION_ACCURACY_HIGH
Indicates the location accuracy level is high.

See Also:
Constant Field Values
Since:
BlackBerry API 7.0.0

LOCATION_ACCURACY_MEDIUM

public static final int LOCATION_ACCURACY_MEDIUM
Indicates the location accuracy level is medium.

See Also:
Constant Field Values
Since:
BlackBerry API 7.0.0

LOCATION_ACCURACY_LOW

public static final int LOCATION_ACCURACY_LOW
Indicates the location accuracy level is low.

See Also:
Constant Field Values
Since:
BlackBerry API 7.0.0

NO_ERROR

public static final int NO_ERROR
Indicates no error.

See Also:
Constant Field Values
Since:
BlackBerry API 7.0.0

LOCATION_DISALLOWED_BY_IT_POLICY

public static final int LOCATION_DISALLOWED_BY_IT_POLICY
Indicates location services are disallowed by an IT policy.

See Also:
Constant Field Values
Since:
BlackBerry API 7.0.0

LOCATION_DISALLOWED_BY_USER

public static final int LOCATION_DISALLOWED_BY_USER
Indicates location services are disallowed by the user.

See Also:
Constant Field Values
Since:
BlackBerry API 7.0.0

TEMPORARILY_UNAVAILABLE_AUTO_RESTART

public static final int TEMPORARILY_UNAVAILABLE_AUTO_RESTART
Indicates current device location is temporarily unavailable. Geofence monitoring is paused and will resume when location is available again.

See Also:
Constant Field Values
Since:
BlackBerry API 7.0.0

OUT_OF_SERVICE

public static final int OUT_OF_SERVICE
Indicates current device location is unavailable. Geofence monitoring will terminate.

See Also:
Constant Field Values
Since:
BlackBerry API 7.0.0

LOW_BATTERY

public static final int LOW_BATTERY
Indicates current device battery level is low. Geofence monitoring will terminate.

See Also:
Constant Field Values
Since:
BlackBerry API 7.0.0


Constructor Detail

Geofence

public Geofence()
Constructs a new Geofence instance.

Since:
BlackBerry API 7.0.0


Method Detail

monitorPerimeter

public int monitorPerimeter(GeofenceListener listener,
                            String tag,
                            Coordinates coordinates,
                            int radius,
                            int accuracyFactor,
                            int duration)
Defines and monitors a circular perimeter for a location of interest during a specified time period.

The device is considered to have entered the area if it was previously outside the perimeter and its current location is now within the perimeter. The device is inside the perimeter until it moves a specified distance (defined by accuracyFactor) beyond the perimeter.

Parameters:
listener - A listener that is implemented by the application to handle geofencing events.
tag - A unique string (for example, "coffee shop") that describes the perimeter to monitor. The tag is used to stop the monitoring request.
coordinates - The location coordinates (latitude-longitude in decimal degrees) for the perimeter's center.
radius - The radius (in meters) for the perimeter.
accuracyFactor - The distance (in meters) beyond the perimeter representing a zone that isn't monitored.
duration - The period of time (in minutes) during which the perimeter is monitored. When the duration is reached, the perimeter monitoring is stopped. If you want to re-start monitoring, you must re-add the area. You can specify -1 to monitor the area for an indefinite period until the process exits.
Returns:
The status of the request, which can be one of the following:
Since:
BlackBerry API 7.0.0

monitorPerimeter

public int monitorPerimeter(GeofenceListener listener,
                            String tag,
                            Coordinates[] coordinates,
                            int accuracyFactor,
                            int duration)
Defines and monitors the perimeter for a polygon area during a specified time period.

The coordinates are the vertices of a simple concave or convex polygon. The device is considered to have entered the area if it was previously outside the perimeter and its current location is now within the perimeter. The device is inside the area until it moves a specified distance (defined by accuracyFactor) beyond the perimeter.

Parameters:
listener - A listener that is implemented by the application to handle geofencing events.
tag - A unique string (for example, "coffee shop") that describes the perimeter to monitor. The tag is used to stop the monitoring request.
coordinates - An ordered set of latitude-longitude values (in decimal degrees) that define the perimeter of the polygon area to monitor. There must be a minimum of 3 and a maximum of 50 unique coordinates. The first and last coordinates are automatically joined by an edge to close off the polygon.
accuracyFactor - The distance (in meters) beyond the perimeter representing a zone that isn't monitored.
duration - The period of time (in minutes) during which the perimeter is monitored. When the duration is reached, the perimeter monitoring is stopped. If you want to re-start monitoring, you must re-add the area. You can specify -1 to monitor the area for an indefinite period until the process exits.
Returns:
The status of the request, which can be one of the following:
Since:
BlackBerry API 7.0.0

removePerimeter

public int removePerimeter(String tag)
Stops monitoring a specified area.

Parameters:
tag - The string tag (for example, "coffee shop") that is associated with the specified area.
Returns:
The status of the request, which can be one of the following:
Since:
BlackBerry API 7.0.0

isInPerimeter

public boolean isInPerimeter(String tag)
                      throws ControlledAccessException,
                             LocationException
Indicates whether the device is on or inside the perimeter of the monitored area.

The current device location is determined from the last known location of the device within the past 30 seconds.

Parameters:
tag - The string tag (for example, "coffee shop") that is associated with the specified area.
Returns:
true if the device's current location is on or inside the perimeter of the monitored area, false otherwise.
Throws:
ControlledAccessException - if the calling application does not have permission to call this method.
LocationException - if the current location cannot be determined.
Since:
BlackBerry API 7.0.0





Copyright 1999-2011 Research In Motion Limited. 295 Phillip Street, Waterloo, Ontario, Canada, N2L 3W8. All Rights Reserved.
Java is a trademark of Oracle America Inc. in the US and other countries.
Legal