Document Maps JavaScript API Reference Manual Basic Class LngLat

LngLat

AMap.LngLat

Construct a geographic coordinate object to describe a point location on the map

new AMap.LngLat(lng: Number, lat: Number, noWrap: Boolean)

Parameter

Attribute

Type

Description

lng

Number

Longitude value

lat

Number

Latitude value

noWrap(?)

Boolean

Whether to automatically correct the longitude value to the range of [-180,180], the default is false. When noWrap is false, passing [190,30] will be automatically corrected to [-170,30]. When noWrap is true, it will not be automatically corrected, which can be used to draw overlays across the date line.

Demo

var lnglat = new AMap.LngLat(77.193045, 28.59086);

Method

setLng(lng)

Latitude value

Parameter:lng(numberLongitude value

Demo:

lnglat.setLng(77.193045);

setLat(lat)

Set latitude value

Parameter:lat(numberLatitude value

Demo:

lnglat.setLat(28.59086);

getLng()

Get longitude value

Parameter:(numberLongitude value

Demo:

lnglat.getLng();

getLat()

Get latitude value

Parameter:(numberLatitude value

Demo:

lnglat.getLat();

equals(another)

Determine if the latitude and longitude coordinates are equal to another set of latitude and longitude coordinates

Parameter:another(LngLatAnother latitude and longitude coordinate

return value:(BooleanIs it equal

Demo:

lnglat.equals(new AMap.LngLat(77.182402, 28.588147));

add(another, noWrap)

Add to another latitude and longitude

Parameter: 

another(LngLat):Another latitude and longitude coordinate

noWrap(boolean): Whether to adjust the longitude value of the sum to the [-180, 180] interval, the default is false, when it is false the sum [190,30] will be automatically corrected to [-170,30], when it is true it will not be automatically corrected, and can be used for cross-date overlay drawing

return value:(LngLatThe result of adding two latitude and longitude coordinates

Demo:

lnglat.add(new AMap.LngLat(77.182402, 28.588147));

subtract(another, noWrap)

Subtract another latitude and longitude

Parameter:

another(LngLat):Another latitude and longitude coordinate

noWrap(boolean):Whether to adjust the longitude value of the sum to the range of [-180,180], default is false, if false, the sum [190,30] will be automatically adjusted to [-170,30], if true, it will not be automatically adjusted and can be used for drawing overlays across date boundaries

return value:(LngLatThe result of subtracting two latitude and longitude coordinates

Demo:

lnglat.subtract(new AMap.LngLat(77.182402, 28.588147));

offset(E, N)

Obtain the coordinate position after moving E meters east and N meters north from the current latitude and longitude position

Parameter: 

E(Number):Movement in the longitude direction, with east as positive

N(Number):Movement in the latitude direction, with north as positive

return value:(LngLatNew latitude and longitude after moving

Demo:

lnglat.offset(10,10);

toString()

LngLat object returned as a string

return value:(StringFormat such as 'lng value, lat value' string

Demo:

lnglat.toString();

toArray()

LngLat object returned as an array

return value:(StringFormat such as: [lng value, lat value] array

Demo:

lnglat.toArray();

distance(lnglat)

Calculate the distance between the current latitude and longitude and another latitude and longitude or the path composed of the latitude and longitude array

Parameter:lnglat(LngLat|[number, number]Latitude and longitude or array of latitude and longitude to be calculated

return value:(numberDistance value in meters

Demo:

lnglat.distance(new AMap.LngLat(77.182402, 28.588147));