AI2 Component  (Version nb184) Class Reference
Inheritance diagram for


interface  LocationSensorListener

Public Member Functions

 LocationSensor (ComponentContainer container)
 LocationSensor (ComponentContainer container, boolean enabled)
void Initialize ()
void LocationChanged (double latitude, double longitude, double altitude, float speed)
void StatusChanged (String provider, String status)
String ProviderName ()
void ProviderName (String providerName)
boolean ProviderLocked ()
void ProviderLocked (boolean lock)
void TimeInterval (int interval)
int TimeInterval ()
void DistanceInterval (int interval)
int DistanceInterval ()
boolean HasLongitudeLatitude ()
boolean HasAltitude ()
boolean HasAccuracy ()
double Longitude ()
double Latitude ()
double Altitude ()
double Accuracy ()
boolean Enabled ()
void Enabled (boolean enabled)
String CurrentAddress ()
double LatitudeFromAddress (String locationName)
double LongitudeFromAddress (String locationName)
List< String > AvailableProviders ()
void RefreshProvider (final String caller)
void onResume ()
void onStop ()
void onDelete ()
void addListener (LocationSensorListener listener)
void removeListener (LocationSensorListener listener)
- Public Member Functions inherited from
HandlesEventDispatching getDispatchDelegate ()

Static Public Attributes

static final int UNKNOWN_VALUE = 0
- Static Public Attributes inherited from
static final String ASSET_DIRECTORY = "component"
static final int ALIGNMENT_NORMAL = 0
static final int ALIGNMENT_CENTER = 1
static final int ALIGNMENT_OPPOSITE = 2
static final int BUTTON_SHAPE_DEFAULT = 0
static final int BUTTON_SHAPE_ROUNDED = 1
static final int BUTTON_SHAPE_RECT = 2
static final int BUTTON_SHAPE_OVAL = 3
static final int COLOR_NONE = 0x00FFFFFF
static final int COLOR_BLACK = 0xFF000000
static final int COLOR_BLUE = 0xFF0000FF
static final int COLOR_CYAN = 0xFF00FFFF
static final int COLOR_DKGRAY = 0xFF444444
static final int COLOR_GRAY = 0xFF888888
static final int COLOR_GREEN = 0xFF00FF00
static final int COLOR_LTGRAY = 0xFFCCCCCC
static final int COLOR_MAGENTA = 0xFFFF00FF
static final int COLOR_ORANGE = 0xFFFFC800
static final int COLOR_PINK = 0xFFFFAFAF
static final int COLOR_RED = 0xFFFF0000
static final int COLOR_WHITE = 0xFFFFFFFF
static final int COLOR_YELLOW = 0xFFFFFF00
static final int COLOR_DEFAULT = 0x00000000
static final String DEFAULT_VALUE_COLOR_NONE = "&H00FFFFFF"
static final String DEFAULT_VALUE_COLOR_BLACK = "&HFF000000"
static final String DEFAULT_VALUE_COLOR_BLUE = "&HFF0000FF"
static final String DEFAULT_VALUE_COLOR_CYAN = "&HFF00FFFF"
static final String DEFAULT_VALUE_COLOR_DKGRAY = "&HFF444444"
static final String DEFAULT_VALUE_COLOR_GRAY = "&HFF888888"
static final String DEFAULT_VALUE_COLOR_GREEN = "&HFF00FF00"
static final String DEFAULT_VALUE_COLOR_ORANGE = "&HFFFFC800"
static final String DEFAULT_VALUE_COLOR_RED = "&HFFFF0000"
static final String DEFAULT_VALUE_COLOR_DEFAULT = "&H00000000"
static final float FONT_DEFAULT_SIZE = 14
static final int SCALING_SCALE_TO_FIT = 1
static final int TYPEFACE_DEFAULT = 0
static final int TYPEFACE_SANSSERIF = 1
static final int TYPEFACE_SERIF = 2
static final int TYPEFACE_MONOSPACE = 3
static final int LENGTH_PREFERRED = -1
static final int LENGTH_FILL_PARENT = -2
static final int LENGTH_UNKNOWN = -3
static final int LENGTH_PERCENT_TAG = -1000
static final int TOAST_LENGTH_SHORT = 0
static final int TOAST_LENGTH_LONG = 1
static final int DIRECTION_NORTH = 1
static final int DIRECTION_NORTHEAST = 2
static final int DIRECTION_EAST = 3
static final int DIRECTION_SOUTHEAST = 4
static final int DIRECTION_SOUTH = -1
static final int DIRECTION_SOUTHWEST = -2
static final int DIRECTION_WEST = -3
static final int DIRECTION_NORTHWEST = -4
static final int DIRECTION_NONE = 0
static final int DIRECTION_MIN = -4
static final int DIRECTION_MAX = 4
static float SLIDER_MIN_VALUE = 10
static float SLIDER_MAX_VALUE = 50

Additional Inherited Members

- Protected Member Functions inherited from
 AndroidNonvisibleComponent (Form form)
- Protected Attributes inherited from
final Form form

Detailed Description

Non-visible component providing location information, including Latitude(), Longitude(), Altitude() (if supported by the device), speed (if supported by the device), and address. This can also perform "geocoding", converting a given address (not necessarily the current one) to a latitude (with the LatitudeFromAddress(String) method) and a longitude (with the LongitudeFromAddress(String) method).

In order to function, the component must have its Enabled(boolean) property set to true{:.logic.block}, and the device must have location sensing enabled through wireless networks or GPS satellites (if outdoors).

Location information might not be immediately available when an app starts. You'll have to wait a short time for a location provider to be found and used, or wait for the LocationChanged(double, double, double, float) event.

The emulator does not emulate sensors on all devices. Code should be tested on a physical device.

Definition at line 81 of file

Constructor & Destructor Documentation

◆ LocationSensor() [1/2] ( ComponentContainer  container)

Creates a new LocationSensor component.

containerignored (because this is a non-visible component)

Definition at line 238 of file

◆ LocationSensor() [2/2] ( ComponentContainer  container,
boolean  enabled 

Creates a new LocationSensor component with a default state of enabled.

containerignored (because this is a non-visible component)
enabledtrue if the LocationSensor is enabled by default, otherwise false.

Definition at line 248 of file

Member Function Documentation

◆ Accuracy()

double ( )

The LocationSensor will be able to locate the device with a varying degree of confidence, based on the quality of satellite, cell towers, and other data used to estimate location. The Accuracy value is the radius in meters around the sensor's detected location. The device has a 68% chance to be located within this radius. More precise location detection will result in a smaller accuracy number, which allows the app to have more confidence where the device is actually located.

If the accuracy is not known, the return value is 0.0

Definition at line 517 of file

◆ addListener()

void ( LocationSensorListener  listener)

Definition at line 775 of file

◆ Altitude()

double ( )

Altitude of the device measured in meters, if available.

Altitude is measured from the World Geodetic System 84 reference ellipsoid, not sea level.

Note that it is difficult for devices to accurately sense altitude. Altitude reported on a phone/tablet can easily be off by 30 meters or more.

Definition at line 500 of file

◆ AvailableProviders()

List<String> ( )

List of available service providers, such as gps or network. This information is provided as a list and in text form.

Definition at line 656 of file

◆ CurrentAddress()

String ( )

Physical street address of the device from Google's map database.

The address might not always be available from the provider, and the address reported may not always be of the building where the device is located.

If Google has no address information available for a particular location, this will return No address available.

Definition at line 569 of file

◆ DistanceInterval() [1/2]

int ( )

Determines the minimum distance interval, in meters, that the sensor will try to use for sending out location updates. For example, if this is set to 50, then the sensor will fire a LocationChanged(double, double, double, float) event only after 50 meters have been traversed. However, the sensor does not guarantee that an update will be received at exactly the distance interval. It may take more than 5 meters to fire an event, for instance.

It is also useful to check against Accuracy() when using this property. When your device is moving, the accuracy of the detected location is constantly changing.

Definition at line 438 of file

◆ DistanceInterval() [2/2]

void ( int  interval)

Definition at line 402 of file

◆ Enabled() [1/2]

boolean ( )

Indicates whether the user has specified that the sensor should listen for location changes and raise the corresponding events.

Definition at line 532 of file

◆ Enabled() [2/2]

void ( boolean  enabled)

If true{:.logic.block}, the LocationSensor will attempt to read location information from GPS, WiFi location, or other means available on the device. This setting does not control whether location information is actually available. Device location must be enabled or disabled in the device settings.

Definition at line 545 of file

◆ HasAccuracy()

boolean ( )

If true{:.logic.block}, the device can report its accuracy level.

Definition at line 463 of file

◆ HasAltitude()

boolean ( )

If true{:.logic.block}, the device can report its altitude.

Definition at line 455 of file

◆ HasLongitudeLatitude()

boolean ( )

If true{:.logic.block}, the device can report longitude and latitude. It is always the case that either both or neither are.

Definition at line 447 of file

◆ Initialize()

void ( )

Definition at line 272 of file

◆ Latitude()

double ( )

The most recently available latitude value in degrees reported to 5 decimal places. If no value is available, 0 will be returned. Latitude is a value between 90 (north) and -90 (south), where 0 marks the Equator.

Definition at line 483 of file

◆ LatitudeFromAddress()

double ( String  locationName)

Derives latitude from the given locationName.

locationNamehuman-readable address
latitude in degrees, 0 if not found.

Definition at line 613 of file

◆ LocationChanged()

void ( double  latitude,
double  longitude,
double  altitude,
float  speed 

Indicates that a new location has been detected. Speed is reported in meters/second Other values match their properties.

Definition at line 284 of file

◆ Longitude()

double ( )

The most recent available longitude value in degrees reported to 5 decimal places. If no value is available, 0 will be returned. Longitude is a value between 180 (east) and -180 (west), where 0 marks the Prime Meridian.

Definition at line 473 of file

◆ LongitudeFromAddress()

double ( String  locationName)

Derives longitude from the given locationName.

locationNamehuman-readable address
longitude in degrees, 0 if not found.

Definition at line 636 of file

◆ onDelete()

void ( )

◆ onResume()

void ( )

◆ onStop()

void ( )

◆ ProviderLocked() [1/2]

boolean ( )

Definition at line 334 of file

◆ ProviderLocked() [2/2]

void ( boolean  lock)

The device will not change the service provider.

It is possible for a device to switch service providers when the current provider is unable to provide adequate location information. ProviderLocked is a Boolean value: true/false. Set to true{:.logic.block} to prevent providers from changing. Set to false{:.logic.block} to allow for automatic switching when necessary.

@internaldoc Indicates whether the sensor should allow the developer to manually change the provider (GPS, GSM, Wifi, etc.) from which location updates are received.

Definition at line 352 of file

◆ ProviderName() [1/2]

String ( )

Indicates the source of the location information. If there is no provider, the string "NO PROVIDER" is returned. This is useful primarily for debugging.

Definition at line 306 of file

◆ ProviderName() [2/2]

void ( String  providerName)

The current service provider. The provider will most likely be either GPS or network.

@internaldoc Change the location provider. If the blocks program changes the name, try to change the provider. Whatever happens now, the provider and the reported name may be switched to Android's preferred provider later. This is primarily for debugging.

Definition at line 324 of file

◆ RefreshProvider()

void ( final String  caller)

Refresh provider attempts to choose and start the best provider unless someone has set and locked the provider. Currently, blocks programmers cannot do that because the relevant methods are not declared as properties.

Definition at line 670 of file

◆ removeListener()

void ( LocationSensorListener  listener)

Definition at line 780 of file

◆ StatusChanged()

void ( String  provider,
String  status 

Indicates that the status of the location provider service has changed, such as when a provider is lost or a new provider starts being used.

Definition at line 293 of file

◆ TimeInterval() [1/2]

int ( )

Determines the minimum time interval, in milliseconds, that the sensor will try to use for sending out location updates. However, location updates will only be received when the location of the phone actually changes, and use of the specified time interval is not guaranteed. For example, if 30000 is used as the time interval, location updates will never be fired sooner than 30000ms, but they may be fired anytime after.

Values smaller than 30000ms (30 seconds) are not practical for most devices. Small values may drain battery and overwork the GPS.

Definition at line 395 of file

◆ TimeInterval() [2/2]

void ( int  interval)

Definition at line 359 of file

Member Data Documentation


final int = 0

Constant returned by Longitude(), Latitude(), and Altitude() if no value could be obtained for them. The client can find this out directly by calling HasLongitudeLatitude() or HasAltitude().

Definition at line 183 of file

The documentation for this class was generated from the following file: