UNPKG

@dderevjanik/termux-api

Version:

This library allows you to interact with your Android device from Node.js using termux-api

31 lines (30 loc) 919 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.location = location; const child_process_1 = require("child_process"); /** * Get the device location * * **Requires permission** `ACCESS_FINE_LOCATION` */ async function location(options = {}) { const opts = { provider: "gps", request: "once", ...options, }; return new Promise((resolve, reject) => { const command = `termux-location -p ${opts.provider} -r ${opts.request}`; (0, child_process_1.exec)(command, (error, stdout, stderr) => { if (error) { return reject(`Error: ${error.message}`); } if (stderr) { return reject(`Error: ${stderr}`); } const output = stdout.trim(); const location = JSON.parse(output); return resolve(location); }); }); }