Created
January 14, 2024 16:00
-
-
Save mrsoftware/c46663e010a21def8f326eb391d5be7b to your computer and use it in GitHub Desktop.
calculate yandex direction based on lat/lng
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Point struct { | |
Lat float64 | |
Lng float64 | |
} | |
func YandexDirectionMapper(old Point, new Point) (float64, float64) { | |
length := math.Sqrt(math.Pow(new.Lng-old.Lng, 2) + math.Pow(new.Lat-old.Lat, 2)) | |
if length == 0 { | |
return 0, 0 | |
} | |
unitX := (new.Lng - old.Lng) / length | |
unitX5 := float64(int64((unitX)*100000)) / 100000 | |
unitY := (new.Lat - old.Lat) / length | |
unitY5 := float64(int64(unitY*100000)) / 100000 | |
return unitX5, unitY5 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment