Mon 21 Jul 22:43:21 CEST 2025
This commit is contained in:
parent
bfea2d213c
commit
ff60b0809d
37
js/geoip/gps5.js
Normal file
37
js/geoip/gps5.js
Normal file
|
@ -0,0 +1,37 @@
|
|||
/* GPS location based on an external database lookup */
|
||||
|
||||
/* requires https */
|
||||
|
||||
var serviceHost="api.beacondb.net",
|
||||
servicePath="/v1/geolocate?key=test";
|
||||
|
||||
|
||||
|
||||
function geolocate (cb) {
|
||||
var https;
|
||||
if (typeof require == 'function') try {
|
||||
https = require('https');
|
||||
} catch (e) { /* TODO Browser */ }
|
||||
if (!https) return cb(new Error('ENETWORK'));
|
||||
var req = https.request({
|
||||
hostname: serviceHost,
|
||||
port: 443,
|
||||
path: servicePath,
|
||||
method: 'GET'
|
||||
}, function (res) {
|
||||
res.on('data', function (d){
|
||||
try {
|
||||
var json = JSON.parse(d);
|
||||
cb(json)
|
||||
} catch (e) { cb(e) };
|
||||
});
|
||||
})
|
||||
|
||||
req.on('error', function (e) {
|
||||
console.error(e);
|
||||
cb(e);
|
||||
});
|
||||
req.end();
|
||||
}
|
||||
|
||||
module.exports = { geolocate : geolocate };
|
Loading…
Reference in New Issue
Block a user