FileDocCategorySizeDatePackage
AndroidGpsLocationProvider.javaAPI DocAndroid 1.5 API5935Wed May 06 22:41:56 BST 2009android.webkit.gears

AndroidGpsLocationProvider

public final class AndroidGpsLocationProvider extends Object implements android.location.LocationListener
GPS provider implementation for Android.

Fields Summary
private static final String
TAG
Logging tag
private android.location.LocationManager
locationManager
Our location manager instance.
private long
nativeObject
The native object ID.
Constructors Summary
public AndroidGpsLocationProvider(android.webkit.WebView webview, long object)


       
    nativeObject = object;
    locationManager = (LocationManager) webview.getContext().getSystemService(
        Context.LOCATION_SERVICE);
    if (locationManager == null) {
      Log.e(TAG,
          "AndroidGpsLocationProvider: could not get location manager.");
      throw new NullPointerException(
          "AndroidGpsLocationProvider: locationManager is null.");
    }
    // Register for location updates.
    try {
      locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,
          this);
    } catch (IllegalArgumentException ex) {
      Log.e(TAG,
          "AndroidLocationGpsProvider: could not register for updates: " + ex);
      throw ex;
    } catch (SecurityException ex) {
      Log.e(TAG,
          "AndroidGpsLocationProvider: not allowed to register for update: "
          + ex);
      throw ex;
    }
  
Methods Summary
private native voidnativeLocationChanged(android.location.Location location, long object)
The native method called when a new location is available.

param
location is the new Location instance to pass to the native side.
param
nativeObject is a pointer to the corresponding AndroidGpsLocationProvider C++ instance.

private native voidnativeProviderError(boolean isDisabled, long object)
The native method called when there is a GPS provder error.

param
isDisabled is true when the error signifies the fact that the GPS HW is disabled. For other errors, this param is always false.
param
nativeObject is a pointer to the corresponding AndroidGpsLocationProvider C++ instance.

public voidonLocationChanged(android.location.Location location)
Called when the location has changed.

param
location The new location, as a Location object.

    Log.i(TAG, "Location changed: " + location);
    nativeLocationChanged(location, nativeObject);
  
public voidonProviderDisabled(java.lang.String provider)
Called when the provider is disabled.

param
provider the name of the location provider that is now disabled.

    Log.i(TAG, "Provider " + provider + " disabled.");
    nativeProviderError(true, nativeObject);
  
public voidonProviderEnabled(java.lang.String provider)
Called when the provider is enabled.

param
provider the name of the location provider that is now enabled.

    Log.i(TAG, "Provider " + provider + " enabled.");
    // No need to notify the native side. It's enough to start sending
    // valid position fixes again.
  
public voidonStatusChanged(java.lang.String provider, int status, android.os.Bundle extras)
Called when the provider status changes.

param
provider the name of the location provider associated with this update.
param
status {@link LocationProvider#OUT_OF_SERVICE} if the provider is out of service, and this is not expected to change in the near future; {@link LocationProvider#TEMPORARILY_UNAVAILABLE} if the provider is temporarily unavailable but is expected to be available shortly; and {@link LocationProvider#AVAILABLE} if the provider is currently available.
param
extras an optional Bundle which will contain provider specific status variables (such as number of satellites).

    Log.i(TAG, "Provider " + provider + " status changed to " + status);
    if (status == LocationProvider.OUT_OF_SERVICE ||
        status == LocationProvider.TEMPORARILY_UNAVAILABLE) {
      nativeProviderError(false, nativeObject);
    }
  
public voidshutdown()
Called when the provider is no longer needed.

    locationManager.removeUpdates(this);
    Log.i(TAG, "GPS provider closed.");