boundingBoxCoordinates method
Calculates eight points on the bounding box and the center of a given circle. At least one geohash of these nine coordinates, truncated to a precision of at most radius, are guaranteed to be prefixes of any geohash that lies within the circle.
@param center The center given as latitude, longitude
.
@param radius The radius of the circle in meters.
@returns The center of the box, and the eight bounding box points.
Implementation
List<GeoPoint> boundingBoxCoordinates(GeoPoint center, double radius) {
double latDegrees = radius / _METERS_PER_DEGREE_LATITUDE;
double latitudeNorth = min(90, center.latitude + latDegrees);
double latitudeSouth = max(-90, center.latitude - latDegrees);
double longDegsNorth = metersToLongitudeDegrees(radius, latitudeNorth);
double longDegsSouth = metersToLongitudeDegrees(radius, latitudeSouth);
double longDegs = max(longDegsNorth, longDegsSouth);
return [
center,
GeoPoint(center.latitude, wrapLongitude(center.longitude - longDegs)),
GeoPoint(center.latitude, wrapLongitude(center.longitude + longDegs)),
GeoPoint(latitudeNorth, center.longitude),
GeoPoint(latitudeNorth, wrapLongitude(center.longitude - longDegs)),
GeoPoint(latitudeNorth, wrapLongitude(center.longitude + longDegs)),
GeoPoint(latitudeSouth, center.longitude),
GeoPoint(latitudeSouth, wrapLongitude(center.longitude - longDegs)),
GeoPoint(latitudeSouth, wrapLongitude(center.longitude + longDegs)),
];
}