Skip to content

Instantly share code, notes, and snippets.

@mrsoftware
Created January 14, 2024 16:00
Show Gist options
  • Save mrsoftware/c46663e010a21def8f326eb391d5be7b to your computer and use it in GitHub Desktop.
Save mrsoftware/c46663e010a21def8f326eb391d5be7b to your computer and use it in GitHub Desktop.
calculate yandex direction based on lat/lng
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