Maps SDK for Web
tt.LngLat
A LngLat object represents a given longitude and latitude coordinate, measured in degrees. This SDK uses longitude, latitude coordinate order (as opposed to latitude, longitude) to match GeoJSON. Note that any SDK method that accepts a LngLat object as an argument or option can also accept an array of two numbers and will perform an implicit conversion. This flexible type can be used like this:
var v1 = new tt.LngLat(-122.420679, 37.772537);
var v2 = [-122.420679, 37.772537];
var v3 = {lon: -122.420679, lat: 37.772537};
Constructor
tt.LngLat([options], lng, lat)
Methods
convert(input): Maps.LngLat Static
Converts an array of two numbers or an object with lng and lat or lon and lat properties to a LngLat object. If a LngLat object is passed in, the function returns it unchanged.
Example
var arr = [-73.9749, 40.7736];
var ll = tt.LngLat.convert(arr);
ll; // = LngLat {lng: -73.9749, lat: 40.7736}
Parameters
Name | Description |
---|---|
input
Maps.LngLat default:None |
An array of two numbers or object to convert, or a LngLat object to return. |
Returns
A new LngLat object, if a conversion occurred, or the original LngLat object.
toArray( ): Array
Returns the coordinates represented as an array of two numbers.
Example
var ll = new tt.LngLat(-73.9749, 40.7736);
ll.toArray(); // = [-73.9749, 40.7736]
Returns
The coordinates represeted as an array of longitude and latitude.
toBounds([radius=0]): Maps.LngLatBounds
Returns a LngLatBounds from the coordinates extended by a given radius.
Example
var ll = new tt.LngLat(-73.9749, 40.7736);
ll.toBounds(100).toArray(); // = [[-73.97501862141328, 40.77351016847229], [-73.97478137858673, 40.77368983152771]]
Parameters
Name | Description |
---|---|
radius
Number default:0 |
Distance in meters from the coordinates to extend the bounds. |
Returns
A new LngLatBounds object representing the coordinates extended by the radius.
toString( ): String
Returns the coordinates represent as a string.
Example
var ll = new tt.LngLat(-73.9749, 40.7736);
ll.toString(); // = "LngLat(-73.9749, 40.7736)"
Returns
The coordinates represented as a string of the format 'LngLat(lng, lat)'.
wrap( ): Maps.LngLat
Returns a new LngLat object whose longitude is wrapped to the range (-180, 180).
Example
var ll = new tt.LngLat(286.0251, 40.7736);
var wrapped = ll.wrap();
wrapped.lng; // = -73.9749
Returns
The wrapped LngLat object.