-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
339 additions
and
224 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package geo | ||
|
||
import ( | ||
"math" | ||
"net" | ||
|
||
"github.com/golang/geo/s2" | ||
) | ||
|
||
type Provider interface { | ||
HasCountry() (bool, error) | ||
GetCountry(ip net.IP) (country, continent string, netmask int) | ||
HasASN() (bool, error) | ||
GetASN(net.IP) (asn string, netmask int, err error) | ||
HasLocation() (bool, error) | ||
GetLocation(ip net.IP) (location *Location, err error) | ||
} | ||
|
||
const MAX_DISTANCE = 360 | ||
|
||
type Location struct { | ||
Country string | ||
Continent string | ||
RegionGroup string | ||
Region string | ||
Latitude float64 | ||
Longitude float64 | ||
Netmask int | ||
} | ||
|
||
func (l *Location) MaxDistance() float64 { | ||
return MAX_DISTANCE | ||
} | ||
|
||
func (l *Location) Distance(to *Location) float64 { | ||
if to == nil { | ||
return MAX_DISTANCE | ||
} | ||
ll1 := s2.LatLngFromDegrees(l.Latitude, l.Longitude) | ||
ll2 := s2.LatLngFromDegrees(to.Latitude, to.Longitude) | ||
angle := ll1.Distance(ll2) | ||
return math.Abs(angle.Degrees()) | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.