Can now accept location

This commit is contained in:
2026-03-08 15:38:28 +08:00
parent 912f9fd0ad
commit 33a7c04e09
12 changed files with 286 additions and 148 deletions

View File

@@ -5,6 +5,14 @@ import (
"sort"
)
type IGeoLocation interface {
HasGeoLocation() bool
Lat() float64
Lon() float64
Dist(lat, lon float64) float64
Register(map[string]struct{}) bool
}
type GeoLocation struct {
Latitude float64
Longitude float64
@@ -19,7 +27,7 @@ func (b GeoLocation) Dist(lat float64, lon float64) float64 {
var dist float64
geodesic.WGS84.Inverse(
lat, lon,
b.Latitude, b.Longitude,
b.Lat(), b.Lon(),
&dist, nil, nil,
)
return dist
@@ -37,13 +45,14 @@ func (b NoGeoLocation) Register(map[string]struct{}) bool {
type GeoLocations []ISearchable
func (m GeoLocations) SortByNearest(p GeoLocation) {
func (m GeoLocations) SortByNearest(p IGeoLocation) {
sort.Slice(m, func(i, j int) bool {
return m[i].Dist(p.Lat(), p.Lon()) < m[j].Dist(p.Lat(), p.Lon())
})
}
func (b GeoLocation) Register(map[string]struct{}) bool {
panic("GeoLocation: Default is called")
return false
}