Leaflet Map LatLng—表示具有特定纬度和经度的地理点

Leaflet Map LatLng—表示具有特定纬度和经度的地理点

Usage example

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:

所有接受LatLng对象的Leaflet方法也以简单数组形式和简单对象形式接受它们(除非另有说明),因此这些行是等价的:

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

Note that LatLng does not inherit from Leaflet’s Class object, which means new classes can’t inherit from it, and new methods can’t be added to it with the include function.

请注意,LatLng不从Leaflet的Class对象继承,这意味着新的类不能从它继承,并且不能使用include函数向它添加新的方法。

Creation

FactoryDescription
L.latLng(<Number> latitude,
 <Number> longitude, <Number>
 altitude?)
Creates an object representing a geographical point with the given latitude and longitude (and optionally altitude).
创建表示具有给定纬度和经度(以及可选的海拔高度)的地理点的对象。
L.latLng(<Array> coords)Expects an array of the form [Number, Number] or [Number, Number, Number] instead.
应为[Number,Number]或[Number、Number、Number]形式的数组。
L.latLng(<Object> coords)Expects an plain object of the form {lat: Number, lng: Number} or {lat: Number, lng: Number, alt: Number} instead.
应为{lat:Number,lng:Number}或{lat:Number,lng:Number,alt:Number}形式的纯对象。

Methods

MethodReturnsDescription
equals(<LatLngotherLatLng
<Number> maxMargin?)
BooleanReturns true if the given LatLng point is at the same position (within a small margin of error). The margin of error can be overridden by setting maxMargin to a small number.
如果给定的LatLng点位于同一位置(在较小的误差范围内),则返回true。通过将maxMargin设置为一个较小的数字,可以覆盖误差范围。
toString()StringReturns a string representation of the point (for debugging purposes).
返回点的字符串表示形式(用于调试)。
distanceTo(<LatLng
otherLatLng)
NumberReturns the distance (in meters) to the given LatLng calculated using the Spherical Law of Cosines.
返回使用球面余弦定律计算的给定LatLng的距离(以米为单位)。
wrap()LatLngReturns a new LatLng object with the longitude wrapped so it’s always between -180 and +180 degrees.
返回一个新的LatLng对象,该对象的经度始终在-180和+180度之间。
toBounds(<Number>
 sizeInMeters)
LatLngBoundsReturns a new LatLngBounds object in which each boundary is sizeInMeters/2 meters apart from the LatLng.
返回一个新的LatLngBounds对象,其中每个边界与LatLng相距sizeInMeters/2米。

Properties

PropertyTypeDescription
latNumberLatitude in degrees
纬度(度)
lngNumberLongitude in degrees
经度(度)
altNumberAltitude in meters (optional)
海拔高度(米)(可选)
0 0 投票数
文章评分
订阅评论
提醒
0 评论
最旧
最新 最多投票
内联反馈
查看所有评论
0
希望看到您的想法,请您发表评论x