LocationRect Class


The LocationRect class, also known as a bounding box, consists of a set of coordinates that are used to represent rectangular area on the map. These are often used for setting the map view but are also useful for doing calculations. A LocationRect object has three properties; center, width and height. The center property is a Location object marking the center of the LocationRect area. The width and height properties are angles in degrees from the center of the LocationRect to the edges. An instance of the LocationRect class can be created using the following code.

LocationRect(center: Location, width: number, height: number)

centerLocationThe location that defines the center of the rectangle.
heightnumberThe height, in degrees, of the rectangle.
widthnumberThe width, in degrees, of the rectangle.

In addition to creating a LocationRect object using center, width and height values the following static methods can be used to create a LocationRect as well:

fromCorners(northwest: Location, southeast: Location)Returns a LocationRect using the specified locations for the northwest and southeast corners.
fromEdges(north:number, west:number, south:number, east:number)Returns a LocationRect using the specified northern and southern latitudes and western and eastern longitudes for the rectangle boundaries.
fromLocations(Location[])Returns a LocationRect using a list of locations or an array of locations.
fromString("north,west,south,east")Creates a LocationRect from a string with the following format: "north,west,south,east". North, west, south and east specify the coordinate number values.

The following is a list of methods that are part of the LocationRect class.

NameReturn TypeDescription
buffer(percentage: number)Scales the size of a LocationRect by multiplying the width and height properties by a percentage.
clone()LocationRectReturns a copy of the LocationRect object.
contains(location: Location)booleanDetermines if a Location is within the LocationRect.
crossesInternationalDateLine()booleanDetermines if the LocationRect crosses the 180th meridian.
getEast()numberReturns the longitude that defines the eastern edge of the LocationRect.
getNorth()numberReturns the latitude that defines the northern edge of the LocationRect.
getNorthwest()LocationReturns the Location that defines the northwest corner of the LocationRect.
getSouth()numberReturns the latitude that defines the southern edge of the LocationRect.
getSoutheast()LocationReturns the Location that defines the southeast corner of the LocationRect.
getWest()numberReturns the latitude that defines the western edge of the LocationRect.
intersects(locationRect: LocationRect)booleanDetermines if one LocationRect intersects with this LocationRect.
splitByInternationalDateLine()LocationRect[]If a LocationRect crosses the international date line, this method splits it into two LocationRect objects and returns them as an array.
toString()stringConverts the LocationRect object to a string.