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
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 downloadGeoLiteCity.datfrom Maxmind.Gives me: