public class

LocationBounds

extends Object
java.lang.Object
   ↳ com.neomades.maps.LocationBounds

Class Overview

An immutable class representing a latitude/longitude aligned rectangle.

Summary

Public Constructors
LocationBounds(Location northEast, Location southWest)
Creates new bounds based on a southwest and a northeast corner.
Public Methods
Location getCenter()
Returns the center of this LocationBounds.
Location getNorthEast()
Northeast corner of the bounds.
Location getSouthWest()
Southwest corner of the bounds.
LocationBounds include(Location point)
Returns a new LocationBounds that extends this LocationBounds to include the given Location point.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public LocationBounds (Location northEast, Location southWest)

Creates new bounds based on a southwest and a northeast corner.

The bounds conceptually include all points where:

  • the latitude is in the range [northeast.latitude, southwest.latitude];
  • the longitude is in the range [southwest.longtitude, northeast.longitude] if southwest.longtitude <= northeast.longitude
  • the longitude is in the range [southwest.longitude, 180), [-180, northeast.longitude] if southwest.longtitude > northeast.longitude.

Parameters
northEast Northeast corner of the bounds.
southWest Southwest corner of the bounds.

Public Methods

public Location getCenter ()

Returns the center of this LocationBounds.

The center is simply the average of the coordinates (taking into account if it crosses the antimeridian). This is approximately the geographical center (it would be exact if the Earth were a perfect sphere). It will not necessarily be the center of the rectangle as drawn on the map due to the Mercator projection.

Returns
  • A Location that is the center of the LocationBounds.

public Location getNorthEast ()

Northeast corner of the bounds.

Returns
  • Northeast corner of the bounds.

public Location getSouthWest ()

Southwest corner of the bounds.

Returns
  • Southwest corner of the bounds.

public LocationBounds include (Location point)

Returns a new LocationBounds that extends this LocationBounds to include the given Location point. This will return the smallest LocationBounds that contains both this and the extra point.

In particular, it will consider extending the bounds both in the eastward and westward directions (one of which may cross the antimeridian) and choose the smaller of the two. In the case that both directions result in a LocationBounds of the same size, this will extend it in the eastward direction.

Parameters
point a Location point to be included in the new bounds
Returns
  • A new LocationBounds that contains this and the extra point.