mobicontrol.location.Location

This class represents a geographic location.

See Location tutorial.

Instances of this class can be stringified with JSON.stringify and then converted back to the Location instance using JSON.parse with the mobicontrol.json.revive parameter.
Check JSON Serialization tutorial for details.

Location

Since:

Members

readonly, nullable altitude :number

The altitude of the location in meters.

Altitude is measured relative to the WGS84 reference ellipsoid. This value is null if the detected location doesn't have altitude.

Since:

readonly, nullable bearing :number

The bearing at the time of this location in degrees.

Bearing is guaranteed to be in the range [0,360). This value is null if the detected location doesn't have bearing.

Since:

readonly, nullable bearingAccuracy :number

The bearing accuracy of this location in degrees.

This value represents the estimated bearing accuracy in degrees of this location at the 68th percentile confidence level. This value is null if the detected location doesn't have bearing accuracy.

Since:

readonly hasFusedProvider :boolean

true if the location was provided by Fused location provider and false otherwise.
Since:

readonly hasGpsProvider :boolean

true if the location was provided by GPS and false otherwise.
Since:

readonly hasNetworkProvider :boolean

true if the location was provided by Network and false otherwise.
Since:

readonly, nullable horizontalAccuracy :number

The horizontal accuracy of this location in meters.

This value represents the estimated horizontal accuracy radius in meters of this location at the 68th percentile confidence level. This value is null if the detected location doesn't have horizontal accuracy.

See also Location tutorial.

Since:
Example
mobicontrol.location.locate(onLocationEvent);

function onLocationEvent(result) {
    if (result.isSuccessful && isWithinRange(result.location, 5)) {
        mobicontrol.log.info("There is at least a 68% chance the device is within 5 m of the meeting point.");
    }
}

function isWithinRange(location, maxAllowedDistance) {
    var meetingPoint = mobicontrol.location.createLocation(40.7575, -73.9858);
    return meetingPoint.distanceTo(location) + location.horizontalAccuracy < maxAllowedDistance;
}

readonly isMock :boolean

true if the location is a mock location and false otherwise.
Since:

readonly latitude :number

The latitude of the location in degrees.
Since:

readonly longitude :number

The longitude of the location in degrees.
Since:

readonly, nullable speed :number

The speed at the time of this location in meters per second.

This value is null if the detected location doesn't have speed.

Since:

readonly, nullable speedAccuracy :number

The speed accuracy of this location in meters per second.

This value represents the estimated speed accuracy in meters per second of this location at the 68th percentile confidence level. This value is null if the detected location doesn't have speed accuracy.

Since:

readonly, nullable time :Date

The time of this location fix. This value is null if the location does not have a time.
Since:

readonly, nullable verticalAccuracy :number

The vertical (altitude) accuracy of this location in meters.

This value represents the estimated vertical accuracy in meters of this location at the 68th percentile confidence level. This value is null if the detected location doesn't have vertical accuracy.

Since:

Methods

distanceTo(location) → {number}

Return the approximate distance in meters between this location and the given location.

Distance is defined using the WGS84 ellipsoid.

See also Location tutorial.

Parameters:
Name Type Description
location mobicontrol.location.Location The target location.
Returns:
number - Distance in meters between this location and the given location.
Since:

isInside(geofence, accuracyopt) → {boolean}

Determine if it is highly probable that the location is inside the geofence.

See also Location tutorial.

Parameters:
Name Type Attributes Description
geofence mobicontrol.location.Geofence The geofence.
accuracy number <optional>
Accuracy in meters. If provided, it is used as a radius of the accuracy circle, instead of the mobicontrol.location.Location#horizontalAccuracy.
Returns:
boolean - true if there is at least a 68% chance that the location is inside the geofence and false otherwise.
Since:
Example
var createLocation = mobicontrol.location.createLocation;
var colosseum = mobicontrol.location.createGeofence([
    createLocation(41.890961, 12.491094),
    createLocation(41.890961, 12.493604),
    createLocation(41.889459, 12.493604),
    createLocation(41.889459, 12.491094)
]);

mobicontrol.location.locate(onLocationEvent);

function onLocationEvent(result) {
    if (result.isSuccessful) {
        if (result.location.isInside(colosseum)) {
            mobicontrol.log.info("Device is likely inside Colosseum");
        } else if (result.location.isOutside(colosseum)) {
            mobicontrol.log.info("Device is likely outside Colosseum");
        } else {
            mobicontrol.log.info("Device is in grey area");
        }
    }
}

isOutside(geofence, accuracyopt) → {boolean}

Determine if it is highly probable that the location is outside the geofence.

See also Location tutorial.

Parameters:
Name Type Attributes Description
geofence mobicontrol.location.Geofence The geofence.
accuracy number <optional>
Accuracy in meters. If provided, it is used as a radius of the accuracy circle, instead of the mobicontrol.location.Location#horizontalAccuracy.
Returns:
boolean - true if there is at least a 68% chance that the location is outside the geofence and false otherwise.
Since:

toJSON() → {object}

Customize JSON stringification behavior.

This function customizes behavior of JSON.stringify(): instead of this Location being serialized, the object returned by toJSON() will be serialized.

Note: This function is intended to be called internally by JSON.stringify(); it is not intended to be called directly.
Check JSON Serialization tutorial for details.

Returns:
object - Native JavaScript object representing this Location.
Since:

withHorizontalAccuracy(accuracy) → {mobicontrol.location.Location}

Set the horizontal accuracy of the location.
Parameters:
Name Type Description
accuracy number The horizontal accuracy in meters, see mobicontrol.location.Location#horizontalAccuracy.
Returns:
mobicontrol.location.Location - This location.
Since: