13.08.2012 Views

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>ACTIONSCRIPT</strong> 3.0 DEVELOPER’S GUIDE<br />

Geolocation<br />

var geo:Geolocation;<br />

if (Geolocation.isSupported)<br />

{<br />

geo = new Geolocation();<br />

geo.addEv<strong>en</strong>tList<strong>en</strong>er(GeolocationEv<strong>en</strong>t.UPDATE, updateHandler);<br />

}<br />

else<br />

{<br />

geoTextField.text = "Geolocation feature not supported";<br />

}<br />

function updateHandler(ev<strong>en</strong>t:GeolocationEv<strong>en</strong>t):void<br />

{<br />

geoTextField.text = "latitude: " + ev<strong>en</strong>t.latitude.toString() + "\n"<br />

+ "longitude: " + ev<strong>en</strong>t.longitude.toString() + "\n"<br />

+ "altitude: " + ev<strong>en</strong>t.altitude.toString()<br />

+ "speed: " + ev<strong>en</strong>t.speed.toString()<br />

+ "heading: " + ev<strong>en</strong>t.heading.toString()<br />

+ "horizontal accuracy: " + ev<strong>en</strong>t.horizontalAccuracy.toString()<br />

+ "vertical accuracy: " + ev<strong>en</strong>t.verticalAccuracy.toString()<br />

}<br />

To use this example, be sure to create the geoTextField text field and add it to the display list before using this code.<br />

You can adjust the desired time interval for geolocation ev<strong>en</strong>ts by calling the setRequestedUpdateInterval()<br />

method of the Geolocation object. This method takes one parameter, interval, which is the requested update interval<br />

in milliseconds:<br />

var geo:Geolocation = new Geolocation();<br />

geo.setRequestedUpdateInterval(10000);<br />

The actual time betwe<strong>en</strong> geolocation updates may be greater or lesser than this value. Any change in the update interval<br />

affects all registered list<strong>en</strong>ers. If you don’t call the setRequestedUpdateInterval() method, the application receives<br />

updates based on the device's default interval.<br />

The user can prev<strong>en</strong>t an application from accessing geolocation data. For example, the iPhone prompts the user wh<strong>en</strong><br />

an application attempts to obtain geolocation data. In response to the prompt, the user can d<strong>en</strong>y the application access<br />

to geolocation data. The Geolocation object dispatches a status ev<strong>en</strong>t wh<strong>en</strong> the user makes access to geolocation data<br />

unavailable. Also, the Geolocation object has a muted property, which is set to true wh<strong>en</strong> the geolocation s<strong>en</strong>sor is<br />

unavailable. The Geolocation object dispatches a status ev<strong>en</strong>t wh<strong>en</strong> the muted property changes. The following code<br />

shows how to detect wh<strong>en</strong> geolocation data is unavailable:<br />

Last updated 6/6/2012<br />

937

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!