New pricing changes went into effect on July 16, 2018. For more information, check out the Guide for Existing Users.

Coordinates

LatLng class

google.maps.LatLng class

A LatLng is a point in geographical coordinates: latitude and longitude.

  • Latitude ranges between -90 and 90 degrees, inclusive. Values above or below this range will be clamped to the range [-90, 90]. This means that if the value specified is less than -90, it will be set to -90. And if the value is greater than 90, it will be set to 90.
  • Longitude ranges between -180 and 180 degrees, inclusive. Values above or below this range will be wrapped so that they fall within the range. For example, a value of -190 will be converted to 170. A value of 190 will be converted to -170. This reflects the fact that longitudes wrap around the globe.
Although the default map projection associates longitude with the x-coordinate of the map, and latitude with the y-coordinate, the latitude coordinate is always written first, followed by the longitude.
Notice that you cannot modify the coordinates of a LatLng. If you want to compute another point, you have to create a new one.

Most methods that accept LatLng objects also accept a LatLngLiteral object, so that the following are equivalent:

 map.setCenter(new google.maps.LatLng(-34, 151));
map.setCenter({lat: -34, lng: 151});

The constructor also accepts literal objects, and converts them to instances of LatLng:

 myLatLng = new google.maps.LatLng({lat: -34, lng: 151}); 

Constructor
LatLng
LatLng(lat, lng[, noWrap])
Parameters: 
  • latnumber
  • lngnumber
  • noWrap (optional):  boolean
Creates a LatLng object representing a geographic point. Latitude is specified in degrees within the range [-90, 90]. Longitude is specified in degrees within the range [-180, 180]. Set noWrap to true to enable values outside of this range. Note the ordering of latitude and longitude.
Methods
equals
equals(other)
Parameters: 
Return Value:  boolean
Comparison function.
lat
lat()
Parameters:  None
Return Value:  number
Returns the latitude in degrees.
lng
lng()
Parameters:  None
Return Value:  number
Returns the longitude in degrees.
toJSON
toJSON()
Parameters:  None
Return Value:  LatLngLiteral
Converts to JSON representation. This function is intended to be used via JSON.stringify.
toString
toString()
Parameters:  None
Return Value:  string
Converts to string representation.
toUrlValue
toUrlValue([precision])
Parameters: 
  • precision (optional):  number
Return Value:  string
Returns a string of the form "lat,lng" for this LatLng. We round the lat/lng values to 6 decimal places by default.

LatLngLiteral interface

google.maps.LatLngLiteral interface

Object literals are accepted in place of LatLng objects, as a convenience, in many places. These are converted to LatLng objects when the Maps API encounters them.

Examples:

 map.setCenter({lat: -34, lng: 151});
new google.maps.Marker({position: {lat: -34, lng: 151}, map: map});

LatLng object literals are not supported in the Geometry library.

Properties
lat
Type:  number
Latitude in degrees. Values will be clamped to the range [-90, 90]. This means that if the value specified is less than -90, it will be set to -90. And if the value is greater than 90, it will be set to 90.
lng
Type:  number
Longitude in degrees. Values outside the range [-180, 180] will be wrapped so that they fall within the range. For example, a value of -190 will be converted to 170. A value of 190 will be converted to -170. This reflects the fact that longitudes wrap around the globe.

LatLngBounds class

google.maps.LatLngBounds class

A LatLngBounds instance represents a rectangle in geographical coordinates, including one that crosses the 180 degrees longitudinal meridian.

Constructor
LatLngBounds
LatLngBounds([sw, ne])
Parameters: 
Constructs a rectangle from the points at its south-west and north-east corners.
Methods
contains
contains(latLng)
Parameters: 
Return Value:  boolean
Returns true if the given lat/lng is in this bounds.
equals
equals(other)
Parameters: 
Return Value:  boolean
Returns true if this bounds approximately equals the given bounds.
extend
extend(point)
Parameters: 
Return Value:  LatLngBounds
Extends this bounds to contain the given point.
getCenter
getCenter()
Parameters:  None
Return Value:  LatLng
Computes the center of this LatLngBounds
getNorthEast
getNorthEast()
Parameters:  None
Return Value:  LatLng
Returns the north-east corner of this bounds.
getSouthWest
getSouthWest()
Parameters:  None
Return Value:  LatLng
Returns the south-west corner of this bounds.
intersects
intersects(other)
Parameters: 
Return Value:  boolean
Returns true if this bounds shares any points with the other bounds.
isEmpty
isEmpty()
Parameters:  None
Return Value:  boolean
Returns if the bounds are empty.
toJSON
toJSON()
Parameters:  None
Return Value:  LatLngBoundsLiteral
Converts to JSON representation. This function is intended to be used via JSON.stringify.
toSpan
toSpan()
Parameters:  None
Return Value:  LatLng
Converts the given map bounds to a lat/lng span.
toString
toString()
Parameters:  None
Return Value:  string
Converts to string.
toUrlValue
toUrlValue([precision])
Parameters: 
  • precision (optional):  number
Return Value:  string
Returns a string of the form "lat_lo,lng_lo,lat_hi,lng_hi" for this bounds, where "lo" corresponds to the southwest corner of the bounding box, while "hi" corresponds to the northeast corner of that box.
union
union(other)
Parameters: 
Return Value:  LatLngBounds
Extends this bounds to contain the union of this and the given bounds.

LatLngBoundsLiteral interface

google.maps.LatLngBoundsLiteral interface

Object literals are accepted in place of LatLngBounds objects throughout the API. These are automatically converted to LatLngBounds objects. All south, west, north and east must be set, otherwise an exception is thrown.

Properties
east
Type:  number
East longitude in degrees. Values outside the range [-180, 180] will be wrapped to the range [-180, 180). For example, a value of -190 will be converted to 170. A value of 190 will be converted to -170. This reflects the fact that longitudes wrap around the globe.
north
Type:  number
North latitude in degrees. Values will be clamped to the range [-90, 90]. This means that if the value specified is less than -90, it will be set to -90. And if the value is greater than 90, it will be set to 90.
south
Type:  number
South latitude in degrees. Values will be clamped to the range [-90, 90]. This means that if the value specified is less than -90, it will be set to -90. And if the value is greater than 90, it will be set to 90.
west
Type:  number
West longitude in degrees. Values outside the range [-180, 180] will be wrapped to the range [-180, 180). For example, a value of -190 will be converted to 170. A value of 190 will be converted to -170. This reflects the fact that longitudes wrap around the globe.

Point class

google.maps.Point class

Constructor
Point
Point(x, y)
Parameters: 
  • xnumber
  • ynumber
A point on a two-dimensional plane.
Methods
equals
equals(other)
Parameters: 
Return Value:  boolean
Compares two Points
toString
toString()
Parameters:  None
Return Value:  string
Returns a string representation of this Point.
Properties
x
Type:  number
The X coordinate
y
Type:  number
The Y coordinate

Size class

google.maps.Size class

Constructor
Size
Size(width, height[, widthUnit, heightUnit])
Parameters: 
  • widthnumber
  • heightnumber
  • widthUnit (optional):  string
  • heightUnit (optional):  string
Two-dimensional size, where width is the distance on the x-axis, and height is the distance on the y-axis.
Methods
equals
equals(other)
Parameters: 
Return Value:  boolean
Compares two Sizes.
toString
toString()
Parameters:  None
Return Value:  string
Returns a string representation of this Size.
Properties
height
Type:  number
The height along the y-axis, in pixels.
width
Type:  number
The width along the x-axis, in pixels.

Padding interface

google.maps.Padding interface

Properties
bottom
Type:  number
Padding for the bottom, in pixels.
left
Type:  number
Padding for the left, in pixels.
right
Type:  number
Padding for the right, in pixels.
top
Type:  number
Padding for the top, in pixels.

Envoyer des commentaires concernant…

Maps JavaScript API
Besoin d'aide ? Consultez notre page d'assistance.