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

func (l LatLngBounds) Contains(ll LatLng) bool {} #132

Closed
mblasi opened this issue Feb 18, 2018 · 5 comments
Closed

func (l LatLngBounds) Contains(ll LatLng) bool {} #132

mblasi opened this issue Feb 18, 2018 · 5 comments

Comments

@mblasi
Copy link

mblasi commented Feb 18, 2018

Hi falks!
Is there any plan to include this into the golang sdk?

In the meanwhile, do you have any recommended way to implement this functionality in my backend?

Regards,
Matías.

@domesticmouse
Copy link
Contributor

We accept pull requests =)

@mblasi
Copy link
Author

mblasi commented Feb 19, 2018

Sure! I'll try.

Do you have any reference implementation or mathematical theory to afford this problem?

Regards,
Matías.

@mblasi
Copy link
Author

mblasi commented Feb 19, 2018

I think the answer over here: https://s2geometry.io/about/overview and https://godoc.org/github.com/golang/geo/s2

Continue researching...

Regards,
Matías.

@mblasi mblasi changed the title func (l LatLngBounds) Contains() bool {} func (l LatLngBounds) Contains(ll LatLng) bool {} Feb 19, 2018
@domesticmouse
Copy link
Contributor

Honestly, the Contains functionality is outside the bounds of what this library is attempting to do, which is be an API client library.

I'd suggest looking http://tile38.com/ for a MIT licensed in-memory geolocation data store, spatial index, and realtime geofence service written in Go. =)

@mblasi
Copy link
Author

mblasi commented Jul 16, 2022

Just for contributing with someone else, this is how I resolved this:

func extendBounds(bounds1, bounds2 maps.LatLngBounds) maps.LatLngBounds {

	boundsPoints := []s2.Point{}
	point1 := s2.PointFromLatLng(s2.LatLngFromDegrees(bounds1.NorthEast.Lng, bounds1.NorthEast.Lat).Normalized())
	point2 := s2.PointFromLatLng(s2.LatLngFromDegrees(bounds1.SouthWest.Lng, bounds1.NorthEast.Lat).Normalized())
	point3 := s2.PointFromLatLng(s2.LatLngFromDegrees(bounds1.SouthWest.Lng, bounds1.SouthWest.Lat).Normalized())
	point4 := s2.PointFromLatLng(s2.LatLngFromDegrees(bounds1.NorthEast.Lng, bounds1.SouthWest.Lat).Normalized())
	boundsPoints = append(boundsPoints, point1, point2, point3, point4)
	point1 = s2.PointFromLatLng(s2.LatLngFromDegrees(bounds2.NorthEast.Lng, bounds2.NorthEast.Lat).Normalized())
	point2 = s2.PointFromLatLng(s2.LatLngFromDegrees(bounds2.SouthWest.Lng, bounds2.NorthEast.Lat).Normalized())
	point3 = s2.PointFromLatLng(s2.LatLngFromDegrees(bounds2.SouthWest.Lng, bounds2.SouthWest.Lat).Normalized())
	point4 = s2.PointFromLatLng(s2.LatLngFromDegrees(bounds2.NorthEast.Lng, bounds2.SouthWest.Lat).Normalized())
	boundsPoints = append(boundsPoints, point1, point2, point3, point4)
	loop := s2.LoopFromPoints(boundsPoints)
	loop.Normalize()

	rect := loop.RectBound()
	hi := rect.Hi()
	lo := rect.Lo()

	return maps.LatLngBounds{NorthEast: maps.LatLng{Lat: hi.Lat.Degrees(), Lng: hi.Lng.Degrees()}, SouthWest: maps.LatLng{Lat: lo.Lat.Degrees(), Lng: lo.Lng.Degrees()}}
}

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

2 participants