Permalink
Browse files

Fix for lat/long

  • Loading branch information...
1 parent f058cf2 commit c1b1583ec4e11ae3855e43b8ae426fd583b42a7c @fiorix committed Mar 15, 2016
Showing with 18 additions and 4 deletions.
  1. +16 −2 apiserver/api.go
  2. +1 −1 apiserver/main.go
  3. +1 −1 cmd/freegeoip/ansible-playbook/freegeoip.yml
View
@@ -12,6 +12,7 @@ import (
"fmt"
"io"
"log"
+ "math"
"math/rand"
"net"
"net/http"
@@ -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 {
@@ -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"`
View
@@ -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() {
@@ -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

0 comments on commit c1b1583

Please sign in to comment.