Package | flash.sensors |
Class | public class Geolocation |
Inheritance | Geolocation EventDispatcher Object |
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 2, Flash Lite 4 |
If a device supports geolocation, you can use this class to obtain the current geographical location of the device. The geographical location is displayed on the device in the form of latitudinal and longitudinal coordinates (in WGS-84 standard format). When the location of the device changes, you can receive updates about the changes. If the device supports this feature, you will be able to obtain information about the altitude, accuracy, heading, speed, and timestamp of the latest change in the location.
AIR profile support: This feature is supported
only on mobile devices. It is not supported on desktop or AIR for TV devices. You can test
for support at run time using the Geolocation.isSupported
property. See
AIR Profile Support for more information regarding API support across multiple profiles.
More examples
Learn more
Property | Defined By | ||
---|---|---|---|
constructor : Object
A reference to the class object or constructor function for a given object instance. | Object | ||
isSupported : Boolean [static] [read-only]
Whether a location sensor is available on the device (true); otherwise false. | Geolocation | ||
muted : Boolean [read-only]
Specifies whether the user has denied access to the geolocation (true)
or allowed access (false). | Geolocation | ||
prototype : Object [static]
A reference to the prototype object of a class or function object. | Object |
Method | Defined By | ||
---|---|---|---|
Creates a new Geolocation instance. | Geolocation | ||
addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
Registers an event listener object with an EventDispatcher object so that the listener
receives notification of an event. | EventDispatcher | ||
Dispatches an event into the event flow. | EventDispatcher | ||
Checks whether the EventDispatcher object has any listeners registered for a specific type
of event. | EventDispatcher | ||
Indicates whether an object has a specified property defined. | Object | ||
Indicates whether an instance of the Object class is in the prototype chain of the object specified
as the parameter. | Object | ||
Indicates whether the specified property exists and is enumerable. | Object | ||
Removes a listener from the EventDispatcher object. | EventDispatcher | ||
Sets the availability of a dynamic property for loop operations. | Object | ||
Used to set the time interval for updates, in milliseconds. | Geolocation | ||
Returns the string representation of this object, formatted according to locale-specific conventions. | Object | ||
Returns the string representation of the specified object. | Object | ||
Returns the primitive value of the specified object. | Object | ||
Checks whether an event listener is registered with this EventDispatcher object or any of
its ancestors for the specified event type. | EventDispatcher |
Event | Summary | Defined By | ||
---|---|---|---|---|
[broadcast event] Dispatched when the Flash Player or AIR application gains operating system focus and becomes active. | EventDispatcher | |||
[broadcast event] Dispatched when the Flash Player or AIR application operating loses system focus and is becoming inactive. | EventDispatcher | |||
The Geolocation object dispatches status events when the user changes access to the location sensor. | Geolocation | |||
The update event is dispatched in response to updates from the location sensor. | Geolocation |
isSupported | property |
muted | property |
muted:Boolean
[read-only] Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 2 |
Specifies whether the user has denied access to the geolocation (true
)
or allowed access (false
). When this value changes,
a status
event is dispatched.
Implementation
public function get muted():Boolean
Related API Elements
Geolocation | () | Constructor |
public function Geolocation()
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 2, Flash Lite 4 |
Creates a new Geolocation instance.
setRequestedUpdateInterval | () | method |
public function setRequestedUpdateInterval(interval:Number):void
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 2, Flash Lite 4 |
Used to set the time interval for updates, in milliseconds. The update interval is only used as a
hint to conserve the battery power. The actual time between location updates may be greater or
lesser than this value.Any change in the update interval using this method
affects all registered update
event listeners. The Geolocation class
can be used without calling the setRequestedUpdateInterval
method.
In this case, the platform will return updates based on its default interval.
Note: First-generation iPhones, which do not include a GPS unit, dispatch
update
events only occasionally. On these devices, a Geolocation object initially
dispatches one or two update
events. It then dispatches update
events
when information changes noticeably.
Parameters
interval:Number — requested update interval. If interval <= 0, then any call to this method
has no effect.
|
Throws
ArgumentError — The specified interval is less than zero.
|
status | Event |
flash.events.StatusEvent
property StatusEvent.type =
flash.events.StatusEvent.STATUS
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 2, Flash Lite 4 |
The Geolocation object dispatches status
events when the user changes access
to the location sensor. For example, if, in response to a device prompt, the user prevents the
application from accessing location data, the Geolcation object dispatches a status
event. When the status changes to a state where the location sensor is not available, the
muted
property of the Geolocation instance is true
.
type
property of a status
event object.
This event has the following properties:
Property | Value |
---|---|
bubbles | false |
cancelable | false ; there is no default behavior to cancel. |
code | A description of the object's status. |
currentTarget | The object that is actively processing the Event object with an event listener. |
level | The category of the message, such as "status" , "warning" or "error" . |
target | The object reporting its status. |
Related API Elements
update | Event |
flash.events.GeolocationEvent
property GeolocationEvent.type =
flash.events.GeolocationEvent.UPDATE
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 2, Flash Lite 4 |
The update
event is dispatched in response to updates from the location sensor. The event
is dispatched under the following circumstances:
- When a new listener function is attached through
addEventListener()
, this event is delivered once to all the registered listeners to provide the current value of the location. - Whenever location updates are obtained from the platform at device determined intervals.
- Whenever the application misses a change in the location (for example, the application is waking up after being asleep).
Note: First-generation iPhones, which do not include a GPS unit, dispatch
update
events only occasionally. On these devices, a Geolocation object initially
dispatches one or two update
events. It then dispatches update
events
when information changes noticeably.
type
property of a GeolocationEvent
event object.
This event has the following properties:
Property | Value |
---|---|
bubbles | false |
cancelable | false ; there is no default behavior to cancel. |
currentTarget | The object that is actively processing the event object with an event listener. |
target | The Geolocation object receiving data. |
update
events
as they are received.
package { import flash.display.Sprite; import flash.display.StageAlign; import flash.display.StageScaleMode; import flash.events.GeolocationEvent; import flash.sensors.Geolocation; import flash.text.TextField; import flash.text.TextFormat; public class GeolocationTest extends Sprite { private var geo:Geolocation; private var log:TextField; public function GeolocationTest() { stage.scaleMode = StageScaleMode.NO_SCALE; stage.align = StageAlign.TOP_LEFT; setUpTextField(); if (Geolocation.isSupported) { geo = new Geolocation(); geo.setRequestedUpdateInterval(100); geo.addEventListener(GeolocationEvent.UPDATE, geolocationUpdateHandler); } else { log.text = "No geolocation support."; } } private function geolocationUpdateHandler(event:GeolocationEvent):void { log.text = "latitude:" + event.latitude.toString() + "°\n"; log.appendText("longitude:" + event.longitude.toString() + "°\n"); log.appendText("horizontal accuracy:" + event.horizontalAccuracy.toString() + " m"); } private function setUpTextField():void { log = new TextField(); var format:TextFormat = new TextFormat("_sans", 24); log.defaultTextFormat = format; log.border = true; log.wordWrap = true; log.multiline = true; log.x = 10; log.y = 10; log.height = stage.stageHeight - 20; log.width = stage.stageWidth - 20; addChild(log); } } }
Mon Nov 28 2011, 06:48 AM -08:00