Advertisement
metalx1000

Open Street Map Scripting GPS - Address

Aug 12th, 2019
1,106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.00 KB | None | 0 0
  1. #!/bin/bash
  2. ######################################################################
  3. #Copyright (C) 2019  Kris Occhipinti
  4. #https://filmsbykris.com
  5.  
  6. #This program is free software: you can redistribute it and/or modify
  7. #it under the terms of the GNU General Public License as published by
  8. #the Free Software Foundation, either version 3 of the License, or
  9. #(at your option) any later version.
  10.  
  11. #This program is distributed in the hope that it will be useful,
  12. #but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. #GNU General Public License for more details.
  15.  
  16. #You should have received a copy of the GNU General Public License
  17. #along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18. ######################################################################
  19.  
  20. function main(){
  21.   log_dir="$HOME/Documents/$(date +%Y)/maps"
  22.   mkdir -p "$log_dir" || (echo "Failed to create $log_dir";exit 1)
  23.   log="$log_dir/location.csv"
  24.  
  25.   open="xdg-open"
  26.   echo "Welcome..."
  27.   read -p "Address: " address
  28.   read -p "Place Name: " name
  29.   url="https://nominatim.openstreetmap.org/search?q=$address&format=json&polygon=1&addressdetails=1"
  30.   output="$(wget -qO- "$url"|jq '.[]|.display_name + "|" + .lat + "," + .lon'|head -n 1)"
  31.   echo "$output"
  32.  
  33.   address="$(echo "$output"|cut -d\| -f1|cut -d\" -f2)"
  34.   gps="$(echo "$output"|cut -d\| -f2|cut -d\" -f1)"
  35.   lat="$(echo "$output"|cut -d\| -f2|cut -d\, -f1|cut -d\" -f1)"
  36.   lon="$(echo "$output"|cut -d\| -f2|cut -d\, -f2|cut -d\" -f1)"
  37.  
  38.   echo "$output"
  39.   osmand="https://osmand.net/go.html?lat=$lat&lon=$lon&z=18"
  40.   echo "$osmand"
  41.   $open "$osmand"
  42.  
  43.   sleep 1
  44.   googlemaps="https://www.google.com/maps/search/$gps/@$gps,17z"
  45.   echo "$googlemaps"
  46.   $open "$googlemaps"
  47.  
  48.   read -p "Add info?" add
  49.   if [ "$add" = "y" ];then
  50.     echo "Adding $address to $log..."
  51.     echo "$name|$address|$gps|$lat|$lon|$osmand|$googlemaps" >> "$log"
  52.     echo "Good-bye..."
  53.   fi
  54.   exit 0
  55. }
  56.  
  57. main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement