Last active
August 30, 2024 18:23
-
-
Save joshooaj/ed0ac6cec921008aeae0b44c4f04158d to your computer and use it in GitHub Desktop.
Measure the distance between two coordinates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function ConvertToGeoCoordinate ([string]$coordinate) { | |
Add-Type -AssemblyName System.Device | |
$lat, $lon = $Coordinate -split ',' | ForEach-Object { | |
[double]$_.Trim() | |
} | |
[device.location.geocoordinate]::new($lat, $lon) | |
} | |
function Measure-Distance { | |
[CmdletBinding()] | |
param ( | |
[Parameter(Mandatory, Position = 0)] | |
[string] | |
$Coordinate1, | |
[Parameter(Mandatory, Position = 1)] | |
[string] | |
$Coordinate2 | |
) | |
process { | |
$coord1 = ConvertToGeoCoordinate -Coordinate $Coordinate1 | |
$coord2 = ConvertToGeoCoordinate -Coordinate $Coordinate2 | |
$coord1.GetDistanceTo($coord2) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment