Legacy

Mapbox.js is no longer in active development. To learn more about our newer mapping tools see Mapbox GL JS.

You are viewing an older version of Mapbox.js. Check out v3.3.1 for the latest.

LatLng

Represents a geographical point with a certain latitude and longitude.

var latlng = L.latLng(50.5, 30.5);

All Leaflet methods that accept LatLng objects also accept them in a simple Array form and simple object form (unless noted otherwise), so these lines are equivalent:

map.panTo([50, 30]);
map.panTo({lon: 30, lat: 50});
map.panTo({lat: 50, lng: 30});
map.panTo(L.latLng(50, 30));

Creation

Factory Description
L.latLng( <Number> latitude, <Number> longitude, <Number> altitude? ) Creates an object representing a geographical point with the given latitude and longitude (and optionally altitude).

Properties

Property Type Description
lat Number Latitude in degrees.
lng Number Longitude in degrees.

Methods

Method Returns Description
distanceTo( <LatLng> otherLatlng ) Number Returns the distance (in meters) to the given LatLng calculated using the Haversine formula. See description on wikipedia
equals( <LatLng> otherLatlng ) Boolean Returns true if the given LatLng point is at the same position (within a small margin of error).
toString() String Returns a string representation of the point (for debugging purposes).
wrap( <Number> left, <Number> right ) LatLng Returns a new LatLng object with the longitude wrapped around left and right boundaries (-180 to 180 by default).

Constants

Constant Type Value Description
DEG_TO_RAD Number Math.PI / 180 A multiplier for converting degrees into radians.
RAD_TO_DEG Number 180 / Math.PI A multiplier for converting radians into degrees.
MAX_MARGIN Number 1.0E-9 Max margin of error for the equality check.