SHARE
TWEET

show_location_in_chrome.sh

a guest Jul 25th, 2013 49 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env bash
  2.  
  3. CHROME_BIN=/opt/google/chrome/chrome
  4.  
  5. function exit_with_error {
  6.     if [ "$GUI" ]; then
  7.         zenity --error --text "$1"
  8.     else
  9.         echo "$1" >&2
  10.     fi
  11.  
  12.     exit 1
  13. }
  14.  
  15. # Parses the output of exif and returns three numbers separated by a space.
  16. function parse_coords_output {
  17.     echo -n "$1" | head -n 1 | sed "s/\s*//g" | sed "s/,/ /g"
  18. }
  19.  
  20. function dms_to_decimal {
  21.     eval "DMS=($1)"
  22.     FORMULA="${DMS[0]} + ((${DMS[1]} * 60) + ${DMS[2]}) / 3600"
  23.     echo "scale=7; $FORMULA" | bc
  24. }
  25.  
  26. if [ ! $# -eq 1 ]; then
  27.     exit_with_error "Expected one argument"
  28. elif [ ! -f "$1" ]; then
  29.     exit_with_error "File doesn't exist: $1"
  30. fi
  31.  
  32. RAW_LATITUDE=$(exif "$1" -t GPSLatitude -m 2>&1)
  33. RAW_LONGITUDE=$(exif "$1" -t GPSLongitude -m 2>&1)
  34.  
  35. if [ ! $? -eq 0 ]; then
  36.     exit_with_error "Couldn't find any coordinate metadata"
  37. fi
  38.  
  39. LAT=$(dms_to_decimal "$(parse_coords_output "$RAW_LATITUDE")")
  40. LNG=$(dms_to_decimal "$(parse_coords_output "$RAW_LONGITUDE")")
  41. URL="http://maps.google.com/?q=loc:$LAT,$LNG"
  42.  
  43. $CHROME_BIN $URL
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top