Rob Baillie
Rob Baillie

Reputation: 3470

Access Android Geolocation using Node.Js under Termux

Has anyone tried to get Location information from an Android phone running Node.Js under Termux.

It's for a simple POC that I'd like to do and I don't want to have to get into the world of full blown Android development (I haven't ever done any), and a simple Node server should suffice for what I want.

(background: it's so I can 'pair' an Amazon Dash button to my phone and when I press the button hijack the broadcast on my phone, augment it with GPS information and then transmit it to an IFTTT applet)

Upvotes: 1

Views: 2320

Answers (1)

Download Termux:API from Google Play to the phone.

termux-location

If it works, this command (termux-location) gives back informations in termux console on phone (ofc my latitude, and longitude is not this, it is a 7 long float irl) :

{
  "latitude": 47.0,
  "longitude": 19.0,
  "altitude": 100,
  "accuracy": 19.0,
  "vertical_accuracy": 0.0,
  "bearing": 0.0,
  "speed": 1.5650451183319092,
  "elapsedMs": 15,
  "provider": "gps"
}

It has gives back nothing for me at first, so I have installed Share GPS app from Google Play and somehow it started to work..

Then download and use npm install -g termux-api package. Nodejs example:

var api = require('termux-api').default;

let result = api.createCommand()
            .location()
            .fromGPSProvider()
            .requestOnce()
            .build()
            .run();
 
result.getOutputObject()
    .then(function(location) {
        console.log('Last known location: ', location);
    });

Gives back as termux-location:

Last known location: {
  "latitude": 47.0,
  "longitude": 19.0,
  "altitude": 100,
  "accuracy": 19.0,
  "vertical_accuracy": 0.0,
  "bearing": 0.0,
  "speed": 1.5650451183319092,
  "elapsedMs": 15,
  "provider": "gps"
}

Upvotes: 0

Related Questions