grid

package
v1.11.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 21, 2026 License: MIT Imports: 4 Imported by: 0

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

type BoundingBox struct {
	MinLat float64
	MinLon float64
	MaxLat float64
	MaxLon float64
}

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"

type Cell

type Cell struct {
	Lat float64
	Lon float64
}

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.

Example: a 20×20 km area with cellSizeKm=1 produces ~400 cells.

func (Cell) GeoCoordinates

func (c Cell) GeoCoordinates() string

GeoCoordinates returns the cell center in "lat,lon" format, ready to pass to gmaps.NewGmapJob as the geoCoordinates parameter.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL