Class: Toybox.Position.Location

Overview

The Location object represents a specific position.

Location objects provide methods for retrieving position coordinates in various formats.

Since:

API Level 1.0.0

Instance Method Summary collapse

Instance Method Details

getProjectedLocation(angle as Numeric, distance as Numeric) as Location

Get a Location object that is offset from the current position by a given distance and angle.

Parameters:

  • angle(Float)

    The angle in radians from north.

  • distance(Float)

    The distance from the current position in meters (m).

Returns:

Since:

API Level 3.0.0

initialize(options as { :latitude as Numeric, :longitude as Numeric, :format as Symbol })

Constructor Create a Location based on a set of coordinates.

Parameters:

  • options(Array)

    An Array of options

    • :latitude(Number)

      The latitude

    • :longitude(Number)

      The longitude

    • :format(Symbol)

      The format of the provided latitude and longitude as one of three possible values:

      • :degrees

      • :radians

      • :semicircles

Example:

using Toybox.Position;
var myLocation = new Position.Location(
    {
        :latitude => 38.856147,
        :longitude => -94.800953,
        :format => :degrees
    }
);

Since:

API Level 1.0.0

toDegrees() as Array<Double>

Get a Location object's coordinates in degrees.

Example:

using Toybox.Position;
using Toybox.System;
Position.enableLocationEvents(Position.LOCATION_ONE_SHOT, method(:onPosition));

function onPosition(info) {
    var myLocation = info.position.toDegrees();
    System.println(myLocation[0]); // latitude (e.g. 38.856147)
    System.println(myLocation[1]); // longitude (e.g -94.800953)
}

Returns:

  • Array

    An Array containing the latitude and longitude as Doubles in a degree format

Since:

API Level 1.0.0

toGeoString(format as CoordinateFormat) as String

Get a String representation a Location object's coordinates.

Parameters:

  • format(Number)

    A Position.GEO_* value

Example:

using Toybox.Position;
using Toybox.System;
var myLocation = new Position.Location(
    {
        :latitude => 38.856147,
        :longitude => -94.800953,
        :format => :degrees
    }
);
var locString = myLocation.toGeoString(Position.GEO_DMS); // N 38 51'22.13" W 94 45' 3.44"

Returns:

  • String

    A formatted coordinate String in the specified format

Since:

API Level 1.0.0

toRadians() as Array<Double>

Get a location object's coordinates in radians.

Example:

using Toybox.Position;
using Toybox.System;
Position.enableLocationEvents(Position.LOCATION_ONE_SHOT, method(:onPosition));

function onPosition(info) {
    var myLocation = info.position.toRadians();
    System.println(myLocation[0]); // latitude (e.g. 0.678197)
    System.println(myLocation[1]); // longitude (e.g -1.654588)
}

Returns:

  • Array

    An Array containing latitude and longitude as Doubles in a radian format

Since:

API Level 1.0.0


Generated Jun 2, 2021 8:26:20 AM