Advertisement
Guest User

show_location_in_chrome.sh

a guest
Jul 25th, 2013
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.00 KB | None | 0 0
  1.  
  2. CHROME_BIN=/opt/google/chrome/chrome
  3.  
  4. function exit_with_error {
  5.     if [ "$GUI" ]; then
  6.         zenity --error --text "$1"
  7.     else
  8.         echo "$1" >&2
  9.     fi
  10.  
  11.     exit 1
  12. }
  13.  
  14. # Parses the output of exif and returns three numbers separated by a space.
  15. function parse_coords_output {
  16.     echo -n "$1" | head -n 1 | sed "s/\s*//g" | sed "s/,/ /g"
  17. }
  18.  
  19. function dms_to_decimal {
  20.     eval "DMS=($1)"
  21.     FORMULA="${DMS[0]} + ((${DMS[1]} * 60) + ${DMS[2]}) / 3600"
  22.     echo "scale=7; $FORMULA" | bc
  23. }
  24.  
  25. if [ ! $# -eq 1 ]; then
  26.     exit_with_error "Expected one argument"
  27. elif [ ! -f "$1" ]; then
  28.     exit_with_error "File doesn't exist: $1"
  29. fi
  30.  
  31. RAW_LATITUDE=$(exif "$1" -t GPSLatitude -m 2>&1)
  32. RAW_LONGITUDE=$(exif "$1" -t GPSLongitude -m 2>&1)
  33.  
  34. if [ ! $? -eq 0 ]; then
  35.     exit_with_error "Couldn't find any coordinate metadata"
  36. fi
  37.  
  38. LAT=$(dms_to_decimal "$(parse_coords_output "$RAW_LATITUDE")")
  39. LNG=$(dms_to_decimal "$(parse_coords_output "$RAW_LONGITUDE")")
  40. URL="http://maps.google.com/?q=loc:$LAT,$LNG"
  41.  
  42. $CHROME_BIN $URL
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement