metalx1000

Get address of photo location by gps

Jul 17th, 2025 (edited)
394
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.97 KB | None | 0 0
  1. # get location data
  2. exiftool -gpslongitude -gpslatitude *
  3. exiftool -location:all *
  4.  
  5. #covnert GPS Format
  6. exiftool -c "%.6f" -location:all *
  7.  
  8. # just GPS
  9. exiftool -c "%.6f" -location:all *|grep "GPS Position"|cut -d\: -f2
  10.  
  11. location="$(exiftool -c "%.6f" -location:all IMG_20250704_082217145_HDR.jpg|grep "GPS Position"|cut -d\: -f2)"
  12. echo $location
  13.  
  14. # get location Address from open streetmaps
  15. # limits 1 per second 2500 requests a day
  16. url="https://nominatim.openstreetmap.org/search?q=${location}&format=json&polygon=1&addressdetails=1"
  17. wget -qO- "$url"
  18. wget -qO- "$url"|jq '.[]|.display_name + "|" + .lat + "," + .lon'
  19. wget -qO- "$url"|jq '.[]|.display_name + "|" + .lat + "," + .lon'|head -n 1
  20. wget -qO- "$url"|jq -r '.[]|.display_name + "|" + .lat + "," + .lon'|head -n 1
  21.  
  22. # script
  23. #!/bin/bash
  24. ######################################################################
  25. #Copyright (C) 2025  Kris Occhipinti
  26. #https://filmsbykris.com
  27.  
  28. #This program is free software: you can redistribute it and/or modify
  29. #it under the terms of the GNU General Public License as published by
  30. #the Free Software Foundation version 3 of the License.
  31.  
  32. #This program is distributed in the hope that it will be useful,
  33. #but WITHOUT ANY WARRANTY; without even the implied warranty of
  34. #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  35. #GNU General Public License for more details.
  36.  
  37. #You should have received a copy of the GNU General Public License
  38. #along with this program.  If not, see <http://www.gnu.org/licenses/>.
  39. ######################################################################
  40.  
  41. for i in *.jpg; do
  42.   gps="$(exiftool -c "%.6f" -location:all "$i" | grep "GPS Position" | cut -d\: -f2)"
  43.   [[ $gps ]] || continue
  44.   url="https://nominatim.openstreetmap.org/search?q=${gps}&format=json&polygon=1&addressdetails=1"
  45.   location="$(wget -qO- "$url" | jq -r '.[]|.display_name + "|" + .lat + "," + .lon' | head -n 1)"
  46.   echo "$i|$location"
  47.   sleep 1
  48. done | tee photo_location.csv
  49.  
Advertisement
Add Comment
Please, Sign In to add comment