AI2 Component  (Version nb184)
com.google.appinventor.components.runtime.LocationSensor Class Reference
Inheritance diagram for com.google.appinventor.components.runtime.LocationSensor:
com.google.appinventor.components.runtime.AndroidNonvisibleComponent com.google.appinventor.components.runtime.Component com.google.appinventor.components.runtime.OnStopListener com.google.appinventor.components.runtime.OnResumeListener com.google.appinventor.components.runtime.Deleteable com.google.appinventor.components.runtime.Component

Classes

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 com.google.appinventor.components.runtime.AndroidNonvisibleComponent
HandlesEventDispatching getDispatchDelegate ()
 

Static Public Attributes

static final int UNKNOWN_VALUE = 0
 
- Static Public Attributes inherited from com.google.appinventor.components.runtime.Component
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 ACCELEROMETER_SENSITIVITY_WEAK = 1
 
static final int ACCELEROMETER_SENSITIVITY_MODERATE = 2
 
static final int ACCELEROMETER_SENSITIVITY_STRONG = 3
 
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_LTGRAY = "&HFFCCCCCC"
 
static final String DEFAULT_VALUE_COLOR_MAGENTA = "&HFFFF00FF"
 
static final String DEFAULT_VALUE_COLOR_ORANGE = "&HFFFFC800"
 
static final String DEFAULT_VALUE_COLOR_PINK = "&HFFFFAFAF"
 
static final String DEFAULT_VALUE_COLOR_RED = "&HFFFF0000"
 
static final String DEFAULT_VALUE_COLOR_WHITE = "&HFFFFFFFF"
 
static final String DEFAULT_VALUE_COLOR_YELLOW = "&HFFFFFF00"
 
static final String DEFAULT_VALUE_COLOR_DEFAULT = "&H00000000"
 
static final float FONT_DEFAULT_SIZE = 14
 
static final int LAYOUT_ORIENTATION_HORIZONTAL = ComponentConstants.LAYOUT_ORIENTATION_HORIZONTAL
 
static final int LAYOUT_ORIENTATION_VERTICAL = ComponentConstants.LAYOUT_ORIENTATION_VERTICAL
 
static final int SCALING_SCALE_PROPORTIONALLY = 0
 
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
 
static float SLIDER_THUMB_VALUE = (SLIDER_MIN_VALUE + SLIDER_MAX_VALUE) / 2.0f
 
static final String DEFAULT_VALUE_TEXT_TO_SPEECH_COUNTRY = ""
 
static final String DEFAULT_VALUE_TEXT_TO_SPEECH_LANGUAGE = ""
 

Additional Inherited Members

- Protected Member Functions inherited from com.google.appinventor.components.runtime.AndroidNonvisibleComponent
 AndroidNonvisibleComponent (Form form)
 
- Protected Attributes inherited from com.google.appinventor.components.runtime.AndroidNonvisibleComponent
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 LocationSensor.java.

Constructor & Destructor Documentation

◆ LocationSensor() [1/2]

com.google.appinventor.components.runtime.LocationSensor.LocationSensor ( ComponentContainer  container)

Creates a new LocationSensor component.

Parameters
containerignored (because this is a non-visible component)

Definition at line 238 of file LocationSensor.java.

◆ LocationSensor() [2/2]

com.google.appinventor.components.runtime.LocationSensor.LocationSensor ( ComponentContainer  container,
boolean  enabled 
)

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

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

Definition at line 248 of file LocationSensor.java.

Member Function Documentation

◆ Accuracy()

double com.google.appinventor.components.runtime.LocationSensor.Accuracy ( )

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 LocationSensor.java.

◆ addListener()

void com.google.appinventor.components.runtime.LocationSensor.addListener ( LocationSensorListener  listener)

Definition at line 775 of file LocationSensor.java.

◆ Altitude()

double com.google.appinventor.components.runtime.LocationSensor.Altitude ( )

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 LocationSensor.java.

◆ AvailableProviders()

List<String> com.google.appinventor.components.runtime.LocationSensor.AvailableProviders ( )

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 LocationSensor.java.

◆ CurrentAddress()

String com.google.appinventor.components.runtime.LocationSensor.CurrentAddress ( )

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 LocationSensor.java.

◆ DistanceInterval() [1/2]

int com.google.appinventor.components.runtime.LocationSensor.DistanceInterval ( )

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 LocationSensor.java.

◆ DistanceInterval() [2/2]

void com.google.appinventor.components.runtime.LocationSensor.DistanceInterval ( int  interval)

Definition at line 402 of file LocationSensor.java.

◆ Enabled() [1/2]

boolean com.google.appinventor.components.runtime.LocationSensor.Enabled ( )

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 LocationSensor.java.

◆ Enabled() [2/2]

void com.google.appinventor.components.runtime.LocationSensor.Enabled ( 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 LocationSensor.java.

◆ HasAccuracy()

boolean com.google.appinventor.components.runtime.LocationSensor.HasAccuracy ( )

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

Definition at line 463 of file LocationSensor.java.

◆ HasAltitude()

boolean com.google.appinventor.components.runtime.LocationSensor.HasAltitude ( )

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

Definition at line 455 of file LocationSensor.java.

◆ HasLongitudeLatitude()

boolean com.google.appinventor.components.runtime.LocationSensor.HasLongitudeLatitude ( )

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 LocationSensor.java.

◆ Initialize()

void com.google.appinventor.components.runtime.LocationSensor.Initialize ( )

Definition at line 272 of file LocationSensor.java.

◆ Latitude()

double com.google.appinventor.components.runtime.LocationSensor.Latitude ( )

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 LocationSensor.java.

◆ LatitudeFromAddress()

double com.google.appinventor.components.runtime.LocationSensor.LatitudeFromAddress ( String  locationName)

Derives latitude from the given locationName.

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

Definition at line 613 of file LocationSensor.java.

◆ LocationChanged()

void com.google.appinventor.components.runtime.LocationSensor.LocationChanged ( 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 LocationSensor.java.

◆ Longitude()

double com.google.appinventor.components.runtime.LocationSensor.Longitude ( )

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 LocationSensor.java.

◆ LongitudeFromAddress()

double com.google.appinventor.components.runtime.LocationSensor.LongitudeFromAddress ( String  locationName)

Derives longitude from the given locationName.

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

Definition at line 636 of file LocationSensor.java.

◆ onDelete()

void com.google.appinventor.components.runtime.LocationSensor.onDelete ( )

◆ onResume()

void com.google.appinventor.components.runtime.LocationSensor.onResume ( )

◆ onStop()

void com.google.appinventor.components.runtime.LocationSensor.onStop ( )

◆ ProviderLocked() [1/2]

boolean com.google.appinventor.components.runtime.LocationSensor.ProviderLocked ( )

Definition at line 334 of file LocationSensor.java.

◆ ProviderLocked() [2/2]

void com.google.appinventor.components.runtime.LocationSensor.ProviderLocked ( 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 LocationSensor.java.

◆ ProviderName() [1/2]

String com.google.appinventor.components.runtime.LocationSensor.ProviderName ( )

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 LocationSensor.java.

◆ ProviderName() [2/2]

void com.google.appinventor.components.runtime.LocationSensor.ProviderName ( 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 LocationSensor.java.

◆ RefreshProvider()

void com.google.appinventor.components.runtime.LocationSensor.RefreshProvider ( 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 LocationSensor.java.

◆ removeListener()

void com.google.appinventor.components.runtime.LocationSensor.removeListener ( LocationSensorListener  listener)

Definition at line 780 of file LocationSensor.java.

◆ StatusChanged()

void com.google.appinventor.components.runtime.LocationSensor.StatusChanged ( 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 LocationSensor.java.

◆ TimeInterval() [1/2]

int com.google.appinventor.components.runtime.LocationSensor.TimeInterval ( )

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 LocationSensor.java.

◆ TimeInterval() [2/2]

void com.google.appinventor.components.runtime.LocationSensor.TimeInterval ( int  interval)

Definition at line 359 of file LocationSensor.java.

Member Data Documentation

◆ UNKNOWN_VALUE

final int com.google.appinventor.components.runtime.LocationSensor.UNKNOWN_VALUE = 0
static

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 LocationSensor.java.


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