Skip to content
Snippets Groups Projects
Commit 76f36d59 authored by Johan de Klerk's avatar Johan de Klerk
Browse files

Merge branch 'main' of gitlab.bob.co.za:bob-public-utils/bobgroup-go-utils

parents 244d12d3 58ea1d59
No related branches found
No related tags found
No related merge requests found
......@@ -3,6 +3,7 @@ package address_utils
import (
"crypto/md5"
"fmt"
"math"
"regexp"
"strings"
......@@ -275,3 +276,23 @@ func GetZoneDisplayName(zone string) string {
return zone
}
func GetDistanceInKmBetweenCoordinates(lat1 float64, lng1 float64, lat2 float64, lng2 float64) float64 {
radlat1 := float64(math.Pi * lat1 / 180)
radlat2 := float64(math.Pi * lat2 / 180)
theta := float64(lng1 - lng2)
radtheta := float64(math.Pi * theta / 180)
dist := math.Sin(radlat1)*math.Sin(radlat2) + math.Cos(radlat1)*math.Cos(radlat2)*math.Cos(radtheta)
if dist > 1 {
dist = 1
}
dist = math.Acos(dist)
dist = dist * 180 / math.Pi
dist = dist * 60 * 1.1515
// Return in kilometers
return dist * 1.609344
}
......@@ -151,6 +151,20 @@ func ConcatP(args ...*string) string {
return s
}
// Concat concatenates all specified non-empty strings with ", " separators
func Concat(args []string, separator string) string {
s := ""
for _, arg := range args {
if arg != "" {
if s != "" {
s += separator
}
s += arg
}
}
return s
}
func ToJSONString(object interface{}) (string, error) {
jsonBytes, err := json.Marshal(&object)
if err != nil {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment