GeoRectBounds
GeoRectBounds represents a rectangular geographic area defined by southwest and northeast corner points. It is used for defining map regions, ground image bounds, and viewport calculations.
Constructor
Section titled “Constructor”class GeoRectBounds( southWest: GeoPoint? = null, northEast: GeoPoint? = null)Properties
Section titled “Properties”Corner Points
Section titled “Corner Points”southWest: GeoPoint?: Southwest corner (bottom-left) of the rectanglenorthEast: GeoPoint?: Northeast corner (top-right) of the rectangleisEmpty: Boolean: Returnstrueif the bounds are not defined
Computed Properties
Section titled “Computed Properties”center: GeoPoint?: Center point of the boundstoSpan(): GeoPoint?: Returns the span (width/height) as a GeoPointInterface
Basic Usage
Section titled “Basic Usage”Creating Bounds
Section titled “Creating Bounds”// Define a rectangular areaval bounds = GeoRectBounds( southWest = GeoPoint.fromLatLong(37.7649, -122.4294), northeast = GeoPoint.fromLatLong(37.7849, -122.4094))
// Empty bounds (to be extended later)val bounds = GeoRectBounds()Dynamic Bounds Construction
Section titled “Dynamic Bounds Construction”Extending Bounds
Section titled “Extending Bounds”The bounds can be dynamically extended to include new points:
fun extend(point: GeoPointInterface)
// Usageval bounds = GeoRectBounds() // Start empty
val points = listOf( GeoPoint.fromLatLong(37.7749, -122.4194), GeoPoint.fromLatLong(37.7849, -122.4094), GeoPoint.fromLatLong(37.7649, -122.4294))
points.forEach { point -> bounds.extend(point) // Bounds grow to include each point}
println("Final bounds: $bounds")Union of Bounds
Section titled “Union of Bounds”val bounds1 = GeoRectBounds( southWest = GeoPoint.fromLatLong(37.7649, -122.4294), northEast = GeoPoint.fromLatLong(37.7749, -122.4194))
val bounds2 = GeoRectBounds( southWest = GeoPoint.fromLatLong(37.7749, -122.4194), northEast = GeoPoint.fromLatLong(37.7849, -122.4094))
val combinedBounds = bounds1.union(bounds2) // Contains both areasPoint and Bounds Testing
Section titled “Point and Bounds Testing”Contains Point
Section titled “Contains Point”fun contains(point: GeoPointInterface): Boolean
// Usageval bounds = GeoRectBounds( southWest = GeoPoint.fromLatLong(37.7649, -122.4294), northEast = GeoPoint.fromLatLong(37.7849, -122.4094))
val testPoint = GeoPoint.fromLatLong(37.7749, -122.4194)val isInside = bounds.contains(testPoint)
println("Point is inside bounds: $isInside")Bounds Intersection
Section titled “Bounds Intersection”fun intersects(other: GeoRectBounds): Boolean
// Usageval bounds1 = GeoRectBounds(/* ... */)val bounds2 = GeoRectBounds(/* ... */)
val doIntersect = bounds1.intersects(bounds2)println("Bounds intersect: $doIntersect")Special Handling
Section titled “Special Handling”International Date Line
Section titled “International Date Line”GeoRectBounds handles rectangles that cross the International Date Line (longitude ±180°):
// Bounds crossing the date lineval pacificBounds = GeoRectBounds( southWest = GeoPoint.fromLatLong(20, 170), // West of date line northEast = GeoPoint.fromLatLong(40, -170) // East of date line)
val pointInPacific = GeoPoint.fromLatLong(30, 175)val containsPoint = pacificBounds.contains(pointInPacific) // trueEmpty Bounds Handling
Section titled “Empty Bounds Handling”val emptyBounds = GeoRectBounds()
println(emptyBounds.isEmpty) // trueprintln(emptyBounds.center) // nullprintln(emptyBounds.toSpan()) // null
// Extending empty boundsemptyBounds.extend(GeoPoint.fromLatLong(37.7749, -122.4194))println(emptyBounds.isEmpty) // falseUtility Methods
Section titled “Utility Methods”String Representation
Section titled “String Representation”// For debuggingval bounds = GeoRectBounds( southWest = GeoPoint.fromLatLong(37.7649, -122.4294), northEast = GeoPoint.fromLatLong(37.7849, -122.4094))
println(bounds.toString())// Output: ((37.7649, -122.4294), (37.7849, -122.4094))URL Value
Section titled “URL Value”fun toUrlValue(precision: Int = 6): String
// Usage for API callsval urlString = bounds.toUrlValue() // "37.764900,-122.429400,37.784900,-122.409400"val preciseString = bounds.toUrlValue(precision = 8)Equality Comparison
Section titled “Equality Comparison”fun equalsTo(other: GeoRectBounds): Boolean
// Usageval bounds1 = GeoRectBounds(/* ... */)val bounds2 = GeoRectBounds(/* ... */)
val areEqual = bounds1.equalsTo(bounds2)