Documentation
¶
Overview ¶
Package grid provides utilities to divide a geographic bounding box into a grid of smaller cells. This is useful for overcoming Google Maps' ~120 results-per-search limit: by splitting a large area into many small cells and issuing one search per cell, you can retrieve far more results.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EstimateCellCount ¶
func EstimateCellCount(bbox BoundingBox, cellSizeKm float64) int
EstimateCellCount returns how many cells GenerateCells would produce without allocating them. Useful for logging or validation.
Types ¶
type BoundingBox ¶
BoundingBox represents a geographic rectangle defined by two corners.
func ParseBoundingBox ¶
func ParseBoundingBox(s string) (BoundingBox, error)
ParseBoundingBox parses a string with format "minLat,minLon,maxLat,maxLon". Example: "40.30,-3.80,40.50,-3.60"
func (BoundingBox) Contains ¶ added in v1.19.0
func (b BoundingBox) Contains(lat, lon float64) bool
Contains reports whether a finite coordinate lies inside the box, including its edges.
type Cell ¶
Cell represents the center point of a grid cell.
func GenerateCells ¶
func GenerateCells(bbox BoundingBox, cellSizeKm float64) []Cell
GenerateCells divides bbox into a grid where each cell is approximately cellSizeKm × cellSizeKm. It returns the center point of every cell.
The longitude step is adjusted for the latitude of the bounding box centre so that cells are roughly square on the ground. Each side is split into a whole number of equal cells (rounding the count up), so the cells cover the entire bounding box and are at most cellSizeKm wide.
Example: a 20×20 km area with cellSizeKm=1 produces ~400 cells.
func (Cell) GeoCoordinates ¶
GeoCoordinates returns the cell center in "lat,lon" format, ready to pass to gmaps.NewGmapJob as the geoCoordinates parameter.