LocationSensor
Definition
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
method) and a longitude (with the LongitudeFromAddress
method).
In order to function, the component must have its Enabled
property set to true
, 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
event.
The emulator does not emulate sensors on all devices. Code should be tested on a physical device.
Properties
- 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. TheAccuracy
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 - 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.
- AvailableProviders
- List of available service providers, such as gps or network. This information is provided as a list and in text form.
- 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
. - 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
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 againstAccuracy
when using this property. When your device is moving, the accuracy of the detected location is constantly changing. - Enabled
- If
true
, theLocationSensor
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. - HasAccuracy
- If
true
, the device can report its accuracy level. - HasAltitude
- If
true
, the device can report its altitude. - HasLongitudeLatitude
- If
true
, the device can report longitude and latitude. It is always the case that either both or neither are. - 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.
- 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.
- ProviderLocked
- 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 totrue
to prevent providers from changing. Set tofalse
to allow for automatic switching when necessary. - ProviderName
- The current service provider. The provider will most likely be either GPS or network.
- 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.