Some termux scripts for use with the GPS functionality of your smartphone. You have to have installed the termux:API
package and also the curl,jq
linux packages. The scripts are using the termux-dialog
utility, to display some nice Android-ish menus, for easy of use.
If you use termux:widget, then you have a quick and nice way to execute these scripts and get GPS data, easy, fast and without Google «interfering» 😉
The first script is getting the weather from the wttr.in
site. It gets your location from your data/internet connection (you can change that) and displays a forecast.
#!/bin/bash loc=$(termux-location -p network -r last) && curl wttr.in/$(echo $loc | jq .latitude),$(echo $loc | jq .longitude) #wait until keypress read -t 3 -n 1
The second one, is for getting and storing your location into a CSV file. This way you can have a kind of POI file. I use it when i want to save a location very quick.
#!/bin/bash function get_location { r="$(termux-dialog sheet -v 'Internet,GPS,Exit')" code=$(echo $r | jq '.code') ans=$(echo $r | jq '.index') if [[ $code -eq 0 ]] then case $ans in 0) loc=$(termux-location -p network -r last) echo "$(echo $loc | jq .latitude);$(echo $loc | jq .longitude);$(echo $loc | jq .accuracy)" ;; 1) loc=$(termux-location) echo "$(echo $loc | jq .latitude);$(echo $loc | jq .longitude);$(echo $loc | jq .accuracy)" ;; 2) echo "-1" ;; esac fi } coords="$(get_location)" if [[ $coords != "-1" ]]; then r="$(termux-dialog text -t 'Enter Description for position' -i $coords)" code=$(echo $r | jq '.code') ans=$(echo $r | jq '.text') if [[ $code -eq -1 ]] then echo "$coords,$ans" >> "$(date +%F).poi" fi fi
Finally the last one, is a Python3 script, which lists all *.poi files, made with the previous script and allowing you to select a stored location and copy the coordinates to the clipboard. This way you can retrieve a location from the .poi files and paste the coordinates to any application in your smartphone (Maps, Browser, SMS etc.).
#!/usr/bin/python import os,sys,csv import subprocess import json def getfile(): files = [f for f in os.listdir('.') if os.path.isfile(f)] s = '' for f in files: if '.poi' in f: s += ','+f s = s[1:] #print(s) result = subprocess.run(['termux-dialog','sheet','-t "hello"','-v '+s], stdout=subprocess.PIPE) s = result.stdout.decode('utf-8') r = json.loads(s) #print(r['code']) if r['code'] == 0: return r['text'] else: return "-1" fn = getfile() if fn != "-1": f = open(fn, 'r') ss ='' with f: reader = csv.reader(f, delimiter=",") results=[] for row in reader: ss += ","+row[3]+' ['+row[0]+' : '+row[1]+']' results.append([row[3],row[0],row[1]]) ss=ss[1:] #print('"'+ss+'"') result = subprocess.run(['termux-dialog','sheet','-t "Locations"','-v '+ss], stdout=subprocess.PIPE) s = result.stdout.decode('utf-8') r = json.loads(s) #print(r['code']) if r['code'] == 0: #print (r['text']) #print (r['index']) os.system('termux-clipboard-set '+results[r['index']][1]+','+results[r['index']][2])