forked from pariz/gountries
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gountries.go
57 lines (43 loc) · 1.5 KB
/
gountries.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package gountries
// BaseLang is a basic structure for common language formatting in the JSON file
type BaseLang struct {
Common string `json:"common"`
Official string `json:"official"`
}
// Geo contains geographical information
type Geo struct {
Region string `json:"region"`
SubRegion string `json:"subregion"`
Continent string // Yaml
Capital string `json:"capital"`
Area float64
}
// Coordinates contains the coordinates for both Country and SubDivision
type Coordinates struct {
LongitudeString string `json:"longitude"`
LatitudeString string `json:"latitude"`
MinLongitude float64
MinLatitude float64
MaxLongitude float64
MaxLatitude float64
Latitude float64
Longitude float64
}
// MeasureDistancePythagoras measures distances betweeen two countries using
// Pythagoras equirect angular equation
func MeasureDistancePythagoras(m1 Measurer, m2 Measurer) (distance float64) {
m1Long, m1Lat := m1.MeasurableCoordinates()
m2Long, m2Lat := m2.MeasurableCoordinates()
return CalculatePythagorasEquirectangular(m1Lat, m1Long, m2Lat, m2Long)
}
// MeasureDistanceHaversine measures distances betweeen two countries using
// Havesine equation
func MeasureDistanceHaversine(m1 Measurer, m2 Measurer) (distance float64) {
m1Long, m1Lat := m1.MeasurableCoordinates()
m2Long, m2Lat := m2.MeasurableCoordinates()
return CalculateHaversine(m1Lat, m1Long, m2Lat, m2Long)
}
// Measurer provides coordinates for measurements
type Measurer interface {
MeasurableCoordinates() (lat, long float64)
}