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 />

var latitude:Number;<br />

var longitude:Number;<br />

if (Geolocation.isSupported)<br />

{<br />

geo = new Geolocation();<br />

if (!geo.muted)<br />

{<br />

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

geo.addEv<strong>en</strong>tList<strong>en</strong>er(StatusEv<strong>en</strong>t.STATUS, geoStatusHandler);<br />

}<br />

}<br />

else<br />

{<br />

trace("not supported");<br />

}<br />

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

{<br />

latitude = ev<strong>en</strong>t.latitude;<br />

longitude = ev<strong>en</strong>t.longitude;<br />

}<br />

function geoStatusHandler(ev<strong>en</strong>t:StatusEv<strong>en</strong>t):void<br />

{<br />

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

}<br />

Note: First-g<strong>en</strong>eration iPhones, which do not include a GPS unit, dispatch update ev<strong>en</strong>ts only occasionally. On these<br />

devices, a Geolocation object initially dispatches one or two update ev<strong>en</strong>ts. It th<strong>en</strong> dispatches update ev<strong>en</strong>ts wh<strong>en</strong><br />

information changes noticeably.<br />

Checking geolocation support<br />

Use the Geolocation.isSupported property to test the runtime <strong>en</strong>vironm<strong>en</strong>t for the ability to use this feature:<br />

if (Geolocation.isSupported)<br />

{<br />

// Set up geolocation ev<strong>en</strong>t list<strong>en</strong>ers and code.<br />

}<br />

Curr<strong>en</strong>tly, geolocation is only supported on ActionScript-based applications for the iPhone and in Flash Lite 4. If<br />

Geolocation.isSupported is true at run time, th<strong>en</strong> geolocation support exists.<br />

Some iPhone models do not have a GPS unit. These models use other means (such as mobile phone triangulation) to<br />

obtain geolocation data. For these models, or on any iPhone that has the GPS disabled, a Geolocation object may only<br />

dispatch one or two initial update ev<strong>en</strong>ts.<br />

Last updated 6/6/2012<br />

938

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

Saved successfully!

Ooh no, something went wrong!