org.placelab.jsr0179
Class LocationProviderImpl

java.lang.Object
  extended byjavax.microedition.location.LocationProvider
      extended byorg.placelab.jsr0179.LocationProviderImpl
All Implemented Interfaces:
EstimateListener

public class LocationProviderImpl
extends javax.microedition.location.LocationProvider
implements EstimateListener


Field Summary
protected static int DEFAULT_INTERVAL
          Default polling interval used for LocationListener's
protected static int DEFAULT_MAXAGE
          The max age an estimate can be before it is considered stale
protected static int DEFAULT_TIMEOUT
          Default timeout when getting a location, in seconds.
 
Fields inherited from class javax.microedition.location.LocationProvider
AVAILABLE, OUT_OF_SERVICE, TEMPORARILY_UNAVAILABLE
 
Constructor Summary
LocationProviderImpl()
           
 
Method Summary
 void addProximityListenerImpl(javax.microedition.location.ProximityListener listener, javax.microedition.location.Coordinates coordinates, float proximityRadius)
           
 void estimateUpdated(Tracker t, Estimate e, Measurement m)
          Implement this method to respond to updates from the Tracker(s) you are registered with.
 javax.microedition.location.Location getLastKnownLocationImpl()
           
 javax.microedition.location.Location getLocation(int timeout)
          Performs a synchronous request for location.
 int getState()
          Returns the current state of this LocationProvider.
 void removeProximityListenerImpl(javax.microedition.location.ProximityListener listener)
           
 void reset()
          Resets the LocationProvider.
 void setLocationListener(javax.microedition.location.LocationListener listener, int interval, int timeout, int maxAge)
          Adds a LocationListener for updates at the defined interval.
 
Methods inherited from class javax.microedition.location.LocationProvider
addProximityListener, getInstance, getLastKnownLocation, removeProximityListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_TIMEOUT

protected static final int DEFAULT_TIMEOUT
Default timeout when getting a location, in seconds.

See Also:
Constant Field Values

DEFAULT_INTERVAL

protected static final int DEFAULT_INTERVAL
Default polling interval used for LocationListener's

See Also:
Constant Field Values

DEFAULT_MAXAGE

protected static final int DEFAULT_MAXAGE
The max age an estimate can be before it is considered stale

See Also:
Constant Field Values
Constructor Detail

LocationProviderImpl

public LocationProviderImpl()
                     throws javax.microedition.location.LocationException
Method Detail

getState

public int getState()
Description copied from class: javax.microedition.location.LocationProvider
Returns the current state of this LocationProvider. The return value shall be one of the availability status code constants defined in this class.

Returns:
the availability state of this LocationProvider

getLocation

public javax.microedition.location.Location getLocation(int timeout)
                                                 throws javax.microedition.location.LocationException,
                                                        java.lang.InterruptedException
Performs a synchronous request for location.

Parameters:
timeout - a timeout value in seconds. -1 is used to indicate that the implementation shall use its default timeout value for this provider.
Returns:
a Location object
Throws:
java.lang.InterruptedException - if the operation is interrupted by calling reset() from another thread
javax.microedition.location.LocationException - if the location couldn't be retrieved or if the timeout period expired

getLastKnownLocationImpl

public javax.microedition.location.Location getLastKnownLocationImpl()

setLocationListener

public void setLocationListener(javax.microedition.location.LocationListener listener,
                                int interval,
                                int timeout,
                                int maxAge)
Description copied from class: javax.microedition.location.LocationProvider
Adds a LocationListener for updates at the defined interval. The listener will be called with updated location at the defined interval. The listener also gets updates when the availablilty state of the LocationProvider changes. Passing in -1 as the interval selects the default interval which is dependent on the used location method. Passing in 0 as the interval registers the listener to only receive provider status updates and not location updates at all. Only one listener can be registered with each LocationProvider instance. Setting the listener replaces any possibly previously set listener. Setting the listener to null cancels the registration of any previously set listener. The implementation shall initiate obtaining the first location result immediately when the listener is registered and provide the location to the listener as soon as it is available. Subsequent location updates will happen at the defined interval after the first one. If the specified update interval is smaller than the time it takes to obtain the first result, the listener shall receive location updates with invalid Locations at the defined interval until the first location result is available. The timeout parameter determines a timeout that is used if it's not possible to obtain a new location result when the update is scheduled to be provided. This timeout value indicates how many seconds the update is allowed to be provided late compared to the defined interval. If it's not possible to get a new location result (interval + timeout) seconds after the previous update, the update will be made and an invalid Location instance is returned. This is also done if the reason for the inability to obtain a new location result is due to the provider being temporarily unavailable or out of service. For example, if the interval is 60 seconds and the timeout is 10 seconds, the update must be delivered at most 70 seconds after the previous update and if no new location result is available by that time the update will be made with an invalid Location instance. The maxAge parameter defines how old the location result is allowed to be provided when the update is made. This allows the implementation to reuse location results if it has a recent location result when the update is due to be delivered. This parameter can only be used to indicate a larger value than the normal time of obtaining a location result by a location method. The normal time of obtaining the location result means the time it takes normally to obtain the result when a request is made. If the application specifies a time value that is less than what can be realized with the used location method, the implementation shall provide as recent location results as are possible with the used location method. For example, if the interval is 60 seconds, the maxAge is 20 seconds and normal time to obtain the result is 10 seconds, the implementation would normally start obtaining the result 50 seconds after the previous update. If there is a location result otherwise available that is more recent than 40 seconds after the previous update, then the maxAge setting to 20 seconds allows to return this result and not start obtaining a new one.

Parameters:
listener - the listener to be registered. If set to null the registration of any previously set listener is cancelled.
interval - the interval in seconds. -1 is used for the default interval of this provider. 0 is used to indicate that the application wants to receive only provider status updates and not location updates at all.
timeout - timeout value in seconds, must be greater than 0. if the value is -1, the default timeout for this provider is used. Also, if the interval is -1 to indicate the default, the value of this parameter has no effect and the default timeout for this provider is used. If the interval is 0, this parameter has no effect.
maxAge - maximum age of the returned location in seconds, must be greater than 0 or equal to -1 to indicate that the default maximum age for this provider is used. Also, if the interval is -1 to indicate the default, the value of this parameter has no effect and the default maximum age for this provider is used. If the interval is 0, this parameter has no effect.

reset

public void reset()
Description copied from class: javax.microedition.location.LocationProvider
Resets the LocationProvider. All pending synchronous location requests will be aborted and any blocked getLocation method calls will terminate with InterruptedException. Applications can use this method e.g. when exiting to have its threads freed from blocking synchronous operations.


addProximityListenerImpl

public void addProximityListenerImpl(javax.microedition.location.ProximityListener listener,
                                     javax.microedition.location.Coordinates coordinates,
                                     float proximityRadius)
                              throws javax.microedition.location.LocationException
Throws:
javax.microedition.location.LocationException

removeProximityListenerImpl

public void removeProximityListenerImpl(javax.microedition.location.ProximityListener listener)

estimateUpdated

public void estimateUpdated(Tracker t,
                            Estimate e,
                            Measurement m)
Description copied from interface: EstimateListener
Implement this method to respond to updates from the Tracker(s) you are registered with.

Specified by:
estimateUpdated in interface EstimateListener
Parameters:
t - the Tracker producing the Estimate
e - the Estimate produced by the Tracker
m - the latest Measurement used by the Tracker to produce the Estimate