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 Lang.Numeric, distance as Lang.Numeric) as Position.Location

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

Parameters:

  • angle(Lang.Float)

    The angle in radians from north.

  • distance(Lang.Float)

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

Returns:

Since:

API Level 3.0.0

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

Constructor Create a Location based on a set of coordinates.

Parameters:

  • options(Lang.Array)

    An Array of options

    • :latitude(Lang.Number)

      The latitude

    • :longitude(Lang.Number)

      The longitude

    • :format(Lang.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 [ Lang.Double, Lang.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:

  • Lang.Array

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

Since:

API Level 1.0.0

toGeoString(format as Position.CoordinateFormat) as Lang.String

Get a String representation a Location object's coordinates.

Parameters:

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:

  • Lang.String

    A formatted coordinate String in the specified format

Since:

API Level 1.0.0

toRadians() as [ Lang.Double, Lang.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:

  • Lang.Array

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

Since:

API Level 1.0.0


Generated Dec 11, 2024, 8:58:43 AM