Skip to content

Commit c1b1583

Browse files
committed
Fix for lat/long
1 parent f058cf2 commit c1b1583

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

apiserver/api.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"fmt"
1313
"io"
1414
"log"
15+
"math"
1516
"math/rand"
1617
"net"
1718
"net/http"
@@ -192,8 +193,8 @@ func (q *geoipQuery) Record(ip net.IP, lang string) *responseRecord {
192193
City: q.City.Names[lang],
193194
ZipCode: q.Postal.Code,
194195
TimeZone: q.Location.TimeZone,
195-
Latitude: q.Location.Latitude,
196-
Longitude: q.Location.Longitude,
196+
Latitude: roundFloat(q.Location.Latitude, .5, 4),
197+
Longitude: roundFloat(q.Location.Longitude, .5, 4),
197198
MetroCode: q.Location.MetroCode,
198199
}
199200
if len(q.Region) > 0 {
@@ -203,6 +204,19 @@ func (q *geoipQuery) Record(ip net.IP, lang string) *responseRecord {
203204
return r
204205
}
205206

207+
func roundFloat(val float64, roundOn float64, places int) (newVal float64) {
208+
var round float64
209+
pow := math.Pow(10, float64(places))
210+
digit := pow * val
211+
_, div := math.Modf(digit)
212+
if div >= roundOn {
213+
round = math.Ceil(digit)
214+
} else {
215+
round = math.Floor(digit)
216+
}
217+
return round / pow
218+
}
219+
206220
type responseRecord struct {
207221
XMLName xml.Name `xml:"Response" json:"-"`
208222
IP string `json:"ip"`

apiserver/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
)
2020

2121
// Version tag.
22-
var Version = "3.1.1"
22+
var Version = "3.1.2"
2323

2424
// Run is the entrypoint for the freegeoip server.
2525
func Run() {

cmd/freegeoip/ansible-playbook/freegeoip.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
- redis
1111
vars:
1212
nodeexporter_url: https://github.com/prometheus/node_exporter/releases/download/0.11.0/node_exporter-0.11.0.linux-amd64.tar.gz
13-
freegeoip_url: https://github.com/fiorix/freegeoip/releases/download/v3.1.1/freegeoip-3.1.1-linux-amd64.tar.gz
13+
freegeoip_url: https://github.com/fiorix/freegeoip/releases/download/v3.1.2/freegeoip-3.1.2-linux-amd64.tar.gz
1414
freegeoip_params:
1515
- -http=:80
1616
- -https=:443

0 commit comments

Comments
 (0)