Places: Round coordinates returned by s2.LatLng() #465 #5080

Signed-off-by: Michael Mayer <michael@photoprism.app>
This commit is contained in:
Michael Mayer
2025-07-01 10:19:39 +02:00
parent 08ae7b0229
commit 318d38a1da
2 changed files with 6 additions and 4 deletions

View File

@@ -177,8 +177,8 @@ func TestLevel(t *testing.T) {
func TestLatLng(t *testing.T) {
t.Run("Valid", func(t *testing.T) {
lat, lng := LatLng("4799e370ca54c8b9")
assert.Equal(t, 48.56344835921243, lat)
assert.Equal(t, 8.996878323369781, lng)
assert.Equal(t, 48.5634484, lat)
assert.Equal(t, 8.9968783, lng)
})
t.Run("Invalid", func(t *testing.T) {

View File

@@ -2,6 +2,8 @@ package s2
import (
gs2 "github.com/golang/geo/s2"
"github.com/photoprism/photoprism/pkg/geo/latlng"
)
// IsZero returns true if the coordinates are both empty.
@@ -32,7 +34,7 @@ func TokenLevel(lat, lng float64, level int) string {
return gs2.CellIDFromLatLng(l).Parent(level).ToToken()
}
// LatLng returns the coordinates for a S2 cell token.
// LatLng returns the rounded coordinates for a S2 cell token.
func LatLng(token string) (lat, lng float64) {
token = NormalizeToken(token)
@@ -48,5 +50,5 @@ func LatLng(token string) (lat, lng float64) {
l := cell.LatLng()
return l.Lat.Degrees(), l.Lng.Degrees()
return latlng.Round(l.Lat.Degrees()), latlng.Round(l.Lng.Degrees())
}