geoip-lite formatting of charecters
Problem
I have this code, which basically looks up an IP address when a user hits the http://domain.tld/stats/1.gif and uses the Geoip-lite library to return lat and long on a raphael map.
var http = require('http'),
util = require('util'),
static = require('node-static'),
faye = require('faye'),
url = require('url'),
geoip = require('geoip-lite');
function LiveStats(options) {
if (! (this instanceof arguments.callee)) {
return new arguments.callee(arguments);
}
...
} else if (location.pathname == '/stats/1.gif' && request.method == 'GET') {
var origin;
response.writeHead(200, {
'Content-Type': 'image/gif'
});
origin = /\/(.*)\.gif/.exec(request.url);
if (origin) {
var ip = request.connection.remoteAddress;
var geo = geoip.lookup(ip);
console.log(geo);
self.bayeux.getClient().publish('/stat', {
title: 'user'
, latitude: geo.ll[0]
, longitude: geo.ll[1]
, ip: ip
});
}
response.end("OK");
} else {
file.serve(request, response);
}
});
});
return server;
};
module.exports = LiveStats;
console.log(geo);
returns for example:
{ range: [ 1391911936, 1391915007 ],
country: 'FR',
region: 'A9',
city: 'N?mes',
ll: [ 43.8333, 4.35 ] }
where the city formatting is all wrong, how should i correct this, so that it prints Nîmes
Many thanks
Solution
I tried your IP address with geoip-lite
, and as you say, 8-bit characters don't seem to work. I have had great luck using geoip, which not only handles wide characters, but it seems to have higher resolution, too. I suggest you try that out, if you can't fix this.
UPDATE: Using geoip
. First you have to download GeoLiteCity.dat
from Maxmind.
var City = require("geoip").City,
city = new City(__dirname + "/GeoLiteCity.dat");
city.lookup("82.246.239.255", function(err, location) {
console.log(location);
}
Gives me:
{ country_code: 'FR',
country_code3: 'FRA',
country_name: 'France',
region: 'A9',
city: 'Nîmes',
latitude: 43.83330154418945,
longitude: 4.349999904632568,
continent_code: 'EU' }
Discussion
View additional discussion.