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
}

View File

@@ -4,7 +4,7 @@ import (
"fmt"
)
func MatchNearest(p GeoLocation, entries *[]ISearchable, dist float64, limit int) (*QueryObject, error) {
func MatchNearest(p IGeoLocation, entries *[]ISearchable, dist float64, limit int) (*QueryObject, error) {
terms := []*QTerm{
{
@@ -19,9 +19,10 @@ func MatchNearest(p GeoLocation, entries *[]ISearchable, dist float64, limit int
locs.SortByNearest(p)
matches := []ISearchable{}
for i, loc := range *locs {
if i < limit {
matches = append(matches, loc)
for i, item := range *locs {
loc := item.(IGeoLocation)
if i < limit && loc.Dist(p.Lat(), p.Lon()) <= dist {
matches = append(matches, item)
}
}

View File

@@ -19,9 +19,14 @@ type QueryObject struct {
Results *[]ISearchable
}
type TableCell struct {
Name string
Value string
}
type IQueryResult interface {
Message() (string, error)
DataType() string
GetTableData() [][]map[string]string
GetTableData() [][]TableCell
Consumed() bool
}