-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeoutil.go
48 lines (38 loc) · 1.12 KB
/
geoutil.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package geolib
import "math"
func DistanceBoundingCheck(slat, slon float64, distance float64) (topLeft GeoLocation, bottomRight GeoLocation) {
radDist := kmToM(distance) / geoEarthMinorAxis
radLat := toRadians(slat)
radLon := toRadians(slon)
_minLat := radLat - radDist
_maxLat := radLat + radDist
var _minLon, _maxLon float64
if _minLat > geoMinLat && _maxLat < geoMaxLat {
deltaLon := math.Asin(math.Sin(radDist) / math.Cos(radLat))
_minLon = radLon - deltaLon
if _minLon < geoMinLon {
_minLon += 2 * geoPI
}
_maxLon = radLon + deltaLon
if _maxLon > geoMaxLon {
_maxLon += 2 * geoPI
}
} else {
_minLat = math.Max(_minLat, geoMinLat)
_maxLat = math.Min(_maxLat, geoMaxLat)
_minLon = geoMinLon
_maxLon = geoMaxLon
}
topLeft = GeoLocation{
lat: toDegrees(_maxLat),
lon: toDegrees(_minLon),
}
bottomRight = GeoLocation{
lat: toDegrees(_minLat),
lon: toDegrees(_maxLon),
}
return
}
func IsGeoLocationInArea(gl *GeoLocation, lTopLeft, lBottomRight *GeoLocation) bool {
return (gl.lat < lTopLeft.lat && gl.lat > lBottomRight.lat) && (gl.lon > lTopLeft.lon && gl.lon < lBottomRight.lon)
}