The LocationService allows the user to provide their location to lens applications if they so desire. For privacy reasons, the user is asked for permission to report location information.

//@input Asset.MapModule mapModule

// Create location handler
var locationService = GeoLocation.createLocationService();

// Set the accuracy
locationService.accuracy = GeoLocationAccuracy.Navigation;

// Get users location.
locationService.getCurrentPosition(
function(geoPosition) {
global.lat = geoPosition.latitude;
global.lng = geoPosition.longitude;
global.heading = geoPosition.heading;
global.isHeadingAvailable = geoPosition.isHeadingAvailable;
global.horizontalAccuracy = geoPosition.horizontalAccuracy;
global.verticalAccuracy = geoPosition.verticalAccuracy;
},
function(error) {
print(error);
}
);

// Setup MapTextureProvider
var location = LocationAsset
.getGeoAnchoredPosition(global.lng, global.lat)
.location.adjacentTile(0,0,-3);
var provider = script.mapModule.createMapTextureProvider();
provider.control.location = location;
script.mesh.mainPass.baseTex = provider;

//Get the postion of the marker
var xy = script.mapModule.longLatToImageRatio(global.lng, global.lat, global.mapProvider.control.location);
var locationService;

script.createEvent("OnStartEvent").bind(function () {
// Create Location Service
locationService = GeoLocation.createLocationService();
locationService.accuracy = GeoLocationAccuracy.High;

var onOrientationUpdate = function (northAlignedOrientation) {
var heading = GeoLocation.getNorthAlignedHeading(northAlignedOrientation);
var rotation = heading * Math.PI / 180;
script.screenTransform.rotation = (quat.fromEulerAngles(0, 0, rotation));
};

locationService.onNorthAlignedOrientationUpdate.add(onOrientationUpdate);
});

// @input SceneObject camera
// @input SceneObject object
// @input Component.DeviceTracking deviceTracking

var locationService;

script.createEvent("OnStartEvent").bind(function () {
// Create Location Service
locationService = GeoLocation.createLocationService();
locationService.accuracy = GeoLocationAccuracy.High;

var onOrientationUpdate = function (northAlignedOrientation) {
var heading = GeoLocation.getNorthAlignedHeading(northAlignedOrientation)

//Calculate difference between device rotation & heading
var deviceRot= script.deviceTracking.getTransform().getLocalRotation();
deviceRot = deviceRot.invert();

// atan2(2qyqw-2qxqz , 1 - 2qy2 - 2qz2)
var deviceYaw = Math.atan2(2 * deviceRot.y * deviceRot.w - 2 * deviceRot.x * deviceRot.z, 1 - 2 * deviceRot.y * deviceRot.y - 2 * deviceRot.z * deviceRot.z);
var deviceYawInDegrees = deviceYaw * 180 / Math.PI;
var headingOffset = (heading - deviceYawInDegrees) * Math.PI / 180;

var gpsWorldRotation = quat.angleAxis(headingOffset, vec3.up());

script.object.getTransform().setWorldPosition(script.camera.getTransform().getWorldPosition());
script.object.getTransform().setLocalRotation(gpsWorldRotation);

};

locationService.onNorthAlignedOrientationUpdate.add(onOrientationUpdate);
});
//@input SceneObject compass

var locationService;

script.createEvent("OnStartEvent").bind(function () {
// Create Location Service
locationService = GeoLocation.createLocationService();
locationService.accuracy = GeoLocationAccuracy.High;

var onOrientationUpdate = function (northAlignedOrientation) {
script.compass.getTransform().setWorldRotation(northAlignedOrientation);
};

locationService.onNorthAlignedOrientationUpdate.add(onOrientationUpdate);
});
interface LocationService {
    accuracy: GeoLocationAccuracy;
    onNorthAlignedOrientationUpdate: event1<quat, void>;
    getCurrentPosition(onSucess: ((geoPosition: GeoPosition) => void), onError: ((error: string) => void)): void;
    getTypeName(): string;
    isOfType(type: string): boolean;
    isSame(other: ScriptObject): boolean;
}

Hierarchy (view full)

Properties

The accuracy of the provided position.

onNorthAlignedOrientationUpdate: event1<quat, void>

Event to notify when north aligned orientation data is available to use.

Methods

  • Exposes User Data

    Retrieves the device's current location. onSuccess: a callback function that takes a GeoPosition object as its sole input parameter. onError: a callback function that takes a string error message as its sole input parameter.

    Parameters

    • onSucess: ((geoPosition: GeoPosition) => void)
        • (geoPosition): void
        • Parameters

          Returns void

    • onError: ((error: string) => void)
        • (error): void
        • Parameters

          • error: string

          Returns void

    Returns void

  • Returns true if the object matches or derives from the passed in type.

    Parameters

    • type: string

    Returns boolean

  • Returns true if this object is the same as other. Useful for checking if two references point to the same thing.

    Parameters

    Returns boolean