Skip to content

Commit

Permalink
Fix for lat/long
Browse files Browse the repository at this point in the history
  • Loading branch information
fiorix committed Mar 15, 2016
1 parent f058cf2 commit c1b1583
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
18 changes: 16 additions & 2 deletions apiserver/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"fmt"
"io"
"log"
"math"
"math/rand"
"net"
"net/http"
Expand Down Expand Up @@ -192,8 +193,8 @@ func (q *geoipQuery) Record(ip net.IP, lang string) *responseRecord {
City: q.City.Names[lang],
ZipCode: q.Postal.Code,
TimeZone: q.Location.TimeZone,
Latitude: q.Location.Latitude,
Longitude: q.Location.Longitude,
Latitude: roundFloat(q.Location.Latitude, .5, 4),
Longitude: roundFloat(q.Location.Longitude, .5, 4),
MetroCode: q.Location.MetroCode,
}
if len(q.Region) > 0 {
Expand All @@ -203,6 +204,19 @@ func (q *geoipQuery) Record(ip net.IP, lang string) *responseRecord {
return r
}

func roundFloat(val float64, roundOn float64, places int) (newVal float64) {
var round float64
pow := math.Pow(10, float64(places))
digit := pow * val
_, div := math.Modf(digit)
if div >= roundOn {
round = math.Ceil(digit)
} else {
round = math.Floor(digit)
}
return round / pow
}

type responseRecord struct {
XMLName xml.Name `xml:"Response" json:"-"`
IP string `json:"ip"`
Expand Down
2 changes: 1 addition & 1 deletion apiserver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
)

// Version tag.
var Version = "3.1.1"
var Version = "3.1.2"

// Run is the entrypoint for the freegeoip server.
func Run() {
Expand Down
2 changes: 1 addition & 1 deletion cmd/freegeoip/ansible-playbook/freegeoip.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
- redis
vars:
nodeexporter_url: http://github.com/prometheus/node_exporter/releases/download/0.11.0/node_exporter-0.11.0.linux-amd64.tar.gz
freegeoip_url: https://github.com/fiorix/freegeoip/releases/download/v3.1.1/freegeoip-3.1.1-linux-amd64.tar.gz
freegeoip_url: https://github.com/fiorix/freegeoip/releases/download/v3.1.2/freegeoip-3.1.2-linux-amd64.tar.gz
freegeoip_params:
- -http=:80
- -https=:443
Expand Down

0 comments on commit c1b1583

Please sign in to comment.