Packagecom.myflashlab.air.extensions.gps
Classpublic class Gps
InheritanceGps Inheritance flash.events.EventDispatcher

Gps extension will let you get current device gps location as fast as possible by automatically checking the best available provider. You don't have to worry about how it works things out. All you need to know is that this extension will check for Satellite, cellular tower and network and it automatically chooses the fastest and the best provider to make sure your app will receive the location information even if you are indoor. This extension is also optimized for the least battery consumtion. Please check out the sample codes to know how to use this extension and what are the best practices to make sure your app is not eating out the battery while reading location information.

Make sure to take care of the permissions manually if you are targeting AIR SDK 24+: https://github.com/myflashlab/GPS-ANE/#permissions

View the examples



Public Properties
 PropertyDefined By
  geocoding : GeocodingManager
[static]
Gps
  geofencing : GeofencingManager
[static]
Gps
  location : LocationManager
[static]
Gps
  state : State
[static]
Gps
Public Methods
 MethodDefined By
  
Gps()
Gps
  
dispose():void
[static] when you're done with this extension, call this method to clean up the memory.
Gps
  
[static] Call this static method only once in your project to have access to all other GPS features
Gps
  
[static] Deprecated, Please use the PermissionCheck ANE instead.
Gps
Public Constants
 ConstantDefined By
  EXTENSION_ID : String = com.myflashlab.air.extensions.gps
[static]
Gps
  VERSION : String = 4.0.3
[static]
Gps
Property Detail
geocodingproperty
public static var geocoding:GeocodingManager

geofencingproperty 
public static var geofencing:GeofencingManager

locationproperty 
public static var location:LocationManager

stateproperty 
public static var state:State

Constructor Detail
Gps()Constructor
public function Gps()



Method Detail
dispose()method
public static function dispose():void

when you're done with this extension, call this method to clean up the memory. you wouldn't need to call this method at all but we added it for your convenient. to stop GPS service, all you need to do is to remove the listener and call Gps.location.stop();

init()method 
public static function init():Gps

Call this static method only once in your project to have access to all other GPS features

Returns
Gps
requestAlwaysAuthorization()method 
public static function requestAlwaysAuthorization():void

Deprecated, Please use the PermissionCheck ANE instead. http://www.myflashlabs.com/product/native-access-permission-check-settings-menu-air-native-extension/

Constant Detail
EXTENSION_IDConstant
public static const EXTENSION_ID:String = com.myflashlab.air.extensions.gps

VERSIONConstant 
public static const VERSION:String = 4.0.3

Examples
The following example shows how to use Gps extension to get location information
    import com.myflashlab.air.extensions.gps.Gps;
    import com.myflashlab.air.extensions.gps.LocationAccuracy;
    import com.myflashlab.air.extensions.gps.Location;
    import com.myflashlab.air.extensions.gps.GpsEvent;
     Gps.init(); // call init only once in your project
     // will return null if no known last location has been found
    Gps.location.getLastLocation(onLocationResult);
     // may take a while depending on when gps info is found
    Gps.location.getCurrentLocation(onLocationResult);
     function onLocationResult($result:Location):void
    {
     if (!$result)
     {
         trace("location is null");
         return;
     }
      trace("accuracy = " + $result.accuracy);
     trace("altitude = " + $result.altitude);
     trace("bearing = " + $result.bearing);
     trace("latitude = " + $result.latitude);
     trace("longitude = " + $result.longitude);
     trace("provider = " + $result.provider);
     trace("speed = " + $result.speed);
     trace("time = " + $result.time);
     trace("---------------------------------");
 }
     // use the start method to get gps information periodically (the gps icon will be shown at your device status bar)
    Gps.location.addEventListener(GpsEvent.LOCATION_UPDATE, onLocationUpdate);
    Gps.location.start(LocationAccuracy.HIGH, 0, 5000);
     // simply stop the gps service when you don't need to get location information periodically anymore.
    Gps.location.removeEventListener(GpsEvent.LOCATION_UPDATE, onLocationUpdate);
    Gps.location.stop();
     function onLocationUpdate(e:GpsEvent):void
    {
     trace(" ------------------------------- onLocationUpdate");
     var loc:Location = e.param;
     trace("accuracy = " + loc.accuracy);
     trace("altitude = " + loc.altitude);
     trace("bearing = " + loc.bearing);
     trace("latitude = " + loc.latitude);
     trace("longitude = " + loc.longitude);
     trace("provider = " + loc.provider);
     trace("speed = " + loc.speed);
     trace("time = " + loc.time);
     trace("---------------------------------");
 }
 
The following example shows how to convert latitude/longitude to human readable address and also how to get gps point info from an address string. This is called geooding reverse and geocoding direct respectfully.
    Gps.geocoding.reverse(-33.7969235, 150.9224326, onResultGeocodingReverse);
     function onResultGeocodingReverse($address:Array):void
    {
     // there might be more than one address found for this location
     trace("$address.length = " + $address.length);
     trace("$address = " + JSON.stringify($address));
     trace("-----------------------------");
 }
     Gps.geocoding.direct("Sydney", onResultGeocodingDirect);
     function onResultGeocodingDirect($location:Array):void
    {
     // there might be more than one location found for this address
     trace("$location.length = " + $location.length);
     trace("$location = " + JSON.stringify($location));
     trace("-----------------------------");
 }