com.googlecode.android_scripting.facade
Class LocationFacade

java.lang.Object
  extended by com.googlecode.android_scripting.jsonrpc.RpcReceiver
      extended by com.googlecode.android_scripting.facade.LocationFacade

public class LocationFacade
extends RpcReceiver

This facade exposes the LocationManager related functionality.

Overview
Once activated by 'startLocating' the LocationFacade attempts to return location data collected via GPS or the cell network. If neither are available the last known location may be retrieved. If both are available the format of the returned data is:
{u'network': {u'altitude': 0, u'provider': u'network', u'longitude': -0.38509020000000002, u'time': 1297079691231L, u'latitude': 52.410557300000001, u'speed': 0, u'accuracy': 75}, u'gps': {u'altitude': 51, u'provider': u'gps', u'longitude': -0.38537094593048096, u'time': 1297079709000L, u'latitude': 52.41076922416687, u'speed': 0, u'accuracy': 24}}
If neither are available {} is returned.
Example (python):

 import android, time
 droid = android.Android()
 droid.startLocating()
 time.sleep(15)
 loc = droid.readLocation().result
 if loc = {}:
   loc = getLastKnownLocation().result
 if loc != {}:
   try:
     n = loc['gps']
   except KeyError:
     n = loc['network'] 
   la = n['latitude'] 
   lo = n['longitude']
   address = droid.geocode(la, lo).result
 droid.stopLocating()
 
The address format is:
[{u'thoroughfare': u'Some Street', u'locality': u'Some Town', u'sub_admin_area': u'Some Borough', u'admin_area': u'Some City', u'feature_name': u'House Numbers', u'country_code': u'GB', u'country_name': u'United Kingdom', u'postal_code': u'ST1 1'}]

Author:
Damon Kohler (damonkohler@gmail.com), Felix Arends (felix.arends@gmail.com)

Constructor Summary
LocationFacade(FacadeManager manager)
           
 
Method Summary
 java.util.List<Address> geocode(java.lang.Double latitude, java.lang.Double longitude, java.lang.Integer maxResults)
           
 java.util.Map<java.lang.String,Location> getLastKnownLocation()
           
 boolean locationProviderEnabled(java.lang.String provider)
           
 java.util.List<java.lang.String> locationProviders()
           
 java.util.Map<java.lang.String,Location> readLocation()
           
 void shutdown()
          Invoked when the receiver is shut down.
 void startLocating(java.lang.Integer minUpdateTime, java.lang.Integer minUpdateDistance)
           
 void stopLocating()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LocationFacade

public LocationFacade(FacadeManager manager)
Method Detail

shutdown

public void shutdown()
Description copied from class: RpcReceiver
Invoked when the receiver is shut down.

Specified by:
shutdown in class RpcReceiver

locationProviders

@Rpc(description="Returns availables providers on the phone")
public java.util.List<java.lang.String> locationProviders()

locationProviderEnabled

@Rpc(description="Ask if provider is enabled")
public boolean locationProviderEnabled(@RpcParameter(name="provider",description="Name of location provider")
                                                      java.lang.String provider)

startLocating

@Rpc(description="Starts collecting location data.")
@RpcStartEvent(value="location")
public void startLocating(@RpcParameter(name="minDistance",description="minimum time between updates in milliseconds")@RpcDefault(value="60000")
                                                            java.lang.Integer minUpdateTime,
                                                            @RpcParameter(name="minUpdateDistance",description="minimum distance between updates in meters")@RpcDefault(value="30")
                                                            java.lang.Integer minUpdateDistance)

readLocation

@Rpc(description="Returns the current location as indicated by all available providers.",
     returns="A map of location information by provider.")
public java.util.Map<java.lang.String,Location> readLocation()

stopLocating

@Rpc(description="Stops collecting location data.")
@RpcStopEvent(value="location")
public void stopLocating()

getLastKnownLocation

@Rpc(description="Returns the last known location of the device.",
     returns="A map of location information by provider.")
public java.util.Map<java.lang.String,Location> getLastKnownLocation()

geocode

@Rpc(description="Returns a list of addresses for the given latitude and longitude.",
     returns="A list of addresses.")
public java.util.List<Address> geocode(@RpcParameter(name="latitude")
                                                             java.lang.Double latitude,
                                                             @RpcParameter(name="longitude")
                                                             java.lang.Double longitude,
                                                             @RpcParameter(name="maxResults",description="maximum number of results")@RpcDefault(value="1")
                                                             java.lang.Integer maxResults)
                                throws java.io.IOException
Throws:
java.io.IOException