-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnative.js
More file actions
42 lines (36 loc) · 838 Bytes
/
native.js
File metadata and controls
42 lines (36 loc) · 838 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
'use strict'
const path = require('path')
const process = require('child_process')
const exe = path.join(__dirname, 'lib', 'macos-location.bin')
const native = (timeout, locate, cb) => {
if ('function' === typeof timeout) {
locate = timeout
timeout = null
}
timeout = timeout || 10000
locate = locate || exe
process.execFile(locate, [], {timeout}, (err, out) => {
if (err) {
if (err.signal === 'SIGTERM') return cb(new Error('timeout'))
return cb(err)
}
try {
out = JSON.parse(out)
} catch (err) {
return cb(err)
}
// macOS provides more details:
// - out.altitude
// - out.direction
// - out.speed
// - out.v_accuracy
// - out.address
cb(null, {
latitude: out.latitude,
longitude: out.longitude,
precision: out.h_accuracy,
native: true
})
})
}
module.exports = native