Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bounds to geohash #40

Open
jtarchie opened this issue Aug 29, 2024 · 0 comments
Open

bounds to geohash #40

jtarchie opened this issue Aug 29, 2024 · 0 comments

Comments

@jtarchie
Copy link

For a project, I was looking for a way to convert a bounds to a geohash. Given the difference in precision levels of geohash, I thought it would get close enough.

Would you be open to a PR adding the feature?

func BoundingBoxToPrecision(bounds Box) {
	geohashPrecisions := [][2]float64{
		{0.0372, 0.0186},
		{0.149, 0.149},
		{1.19, 0.596},
		{4.77, 4.77},
		{38.2, 19.1},
		{153, 153},
		{1220, 610},
		{4890, 4890},
		{39100, 19500},
		{156000, 156000},
		{1250000, 625000},
		{5000000, 5000000},
	}

	height := 111131.75 * (b.MaxLat[1] - b.MinLat[1])

	for index, precision := range geohashPrecisions {
		if height <= precision[0] {
			return max(0, uint(len(geohashPrecisions) - index))
		}
	}

	return uint(len(geohashPrecisions))
} 

Example implementation is above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant