45 lines
1.0 KiB
Go
45 lines
1.0 KiB
Go
package utils
|
|
|
|
import (
|
|
"fmt"
|
|
"math"
|
|
)
|
|
|
|
func CalculateDistance(lat1, lon1, lat2, lon2 float64) float64 {
|
|
const earthRadiusKm = 6371
|
|
const metersPerKm = 1000
|
|
|
|
lat1Rad := DegreesToRadians(lat1)
|
|
lon1Rad := DegreesToRadians(lon1)
|
|
lat2Rad := DegreesToRadians(lat2)
|
|
lon2Rad := DegreesToRadians(lon2)
|
|
|
|
dLat := lat2Rad - lat1Rad
|
|
dLon := lon2Rad - lon1Rad
|
|
|
|
a := math.Sin(dLat/2)*math.Sin(dLat/2) +
|
|
math.Cos(lat1Rad)*math.Cos(lat2Rad)*
|
|
math.Sin(dLon/2)*math.Sin(dLon/2)
|
|
|
|
c := 2 * math.Atan2(math.Sqrt(a), math.Sqrt(1-a))
|
|
return earthRadiusKm * c * metersPerKm
|
|
}
|
|
|
|
func DegreesToRadians(degrees float64) float64 {
|
|
return degrees * math.Pi / 180
|
|
}
|
|
|
|
func GetDeliveryStatusMessage(status string) string {
|
|
messages := map[string]string{
|
|
"assigned": "Commande assignée",
|
|
"en_route": "En route vers le client",
|
|
"arrived": "Arrivé à destination",
|
|
"livre": "Livraison effectuée",
|
|
"cancelled": "Livraison annulée",
|
|
}
|
|
if msg, ok := messages[status]; ok {
|
|
return msg
|
|
}
|
|
return fmt.Sprintf("Statut changé: %s", status)
|
|
}
|