Processing Ajax...

Title

Message

Confirm

Confirm

Confirm

Confirm

Are you sure you want to delete this item?

Confirm

Are you sure you want to delete this item?

Show picture location on Google Maps

Description
Select one or more photos in File Explorer, then run this macro to open Google Maps to the location that's in the image metadata.
Language
C#.net
Minimum Version
Created By
KarolPiechoczek
Contributors
-
Date Created
Apr 26, 2022
Date Last Modified
Apr 26, 2022

Scripted Function (Macro) Code

using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;
using System.Diagnostics;
using System.Globalization;
// The 'windowHandle' parameter will contain the window handle for the:
//   - Active window when run by hotkey
//   - Trigger target when run by a Trigger rule
//   - TitleBar Button owner when run by a TitleBar Button
//   - Jump List owner when run from a Taskbar Jump List
//   - Currently focused window if none of these match
public static class DisplayFusionFunction
{
	public static void Run(IntPtr windowHandle)
	{
		BFS.Clipboard.Copy();
		NumberFormatInfo doubleSeparator = new NumberFormatInfo();
        doubleSeparator.NumberDecimalSeparator = ".";
		
		foreach (string pictureFiles in Clipboard.GetFileDropList())
        {
			Bitmap bitmap = new Bitmap(pictureFiles);
			var longitude = GetCoordinateDouble(bitmap.GetPropertyItem(4));  
            var latitude = GetCoordinateDouble(bitmap.GetPropertyItem(2));
            Process.Start($"https://www.google.com/maps/preview?q={latitude.ToString(doubleSeparator)},{longitude.ToString(doubleSeparator)}"); 
		}
	}
			
	private static double GetCoordinateDouble(PropertyItem propItem)  
    {  
        uint degreesNumerator = BitConverter.ToUInt32(propItem.Value, 0);  
        uint degreesDenominator = BitConverter.ToUInt32(propItem.Value, 4);  
        double degrees = degreesNumerator / (double)degreesDenominator;  
  
        uint minutesNumerator = BitConverter.ToUInt32(propItem.Value, 8);  
        uint minutesDenominator = BitConverter.ToUInt32(propItem.Value, 12);  
        double minutes = minutesNumerator / (double)minutesDenominator;  
  
        uint secondsNumerator = BitConverter.ToUInt32(propItem.Value, 16);  
        uint secondsDenominator = BitConverter.ToUInt32(propItem.Value, 20);  
        double seconds = secondsNumerator / (double)secondsDenominator;  
  
        double coorditate = degrees + (minutes / 60d) + (seconds / 3600d);  
  
        return coorditate;  
    }
}