Back

Locator

The Locator component can be used to find your whereabouts on the planet using either your device's GPS or information from your network.

Create a Locator object using the CreateLocator method of the app object:

 loc = app.CreateLocator( Provider );

Provider can be "GPS", or "Network" or "GPS,Network"
"Network" means get the location from the cell network and wifi, "GPS" tells the locator to use the device's GPS

The SetOnChange method is used to set a function to be called when your calculated position changes.

 loc.SetOnChange( callback );

The Start method starts the object calculating your position.

 loc.Start( );

Once the Start method has been called, the OnChange callback function is the best place to check your position.

Example

function OnStart()
{
    loc = app.CreateLocator("GPS,Network");
    loc.SetOnChange(loc_OnChange);
    loc.Start();
    app.ShowPopup("Locating");
}

function loc_OnChange(pos)
{
    var msg = pos.latitude + ", " + pos.longitude;
    app.ShowPopup( msg );
}
    Copy     Copy All      Run     

The callback function provides a single argument pos which has the following properties

  pos.latitude - degrees
  pos.longitude - degrees
  pos.provider - "GPS" or "Network"
  pos.speed - metres per second
  pos.altitude - metres
  pos.bearing - degrees
  pos.accuracy - (estimated) in metres

See 'CreateLocator for more informations and a complete function list