Skip to content

Instantly share code, notes, and snippets.

@joshooaj
Last active August 30, 2024 18:23
Show Gist options
  • Save joshooaj/ed0ac6cec921008aeae0b44c4f04158d to your computer and use it in GitHub Desktop.
Save joshooaj/ed0ac6cec921008aeae0b44c4f04158d to your computer and use it in GitHub Desktop.
Measure the distance between two coordinates
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