PowerShell script for reverse geo-coding using Windows Location Services

734 Views Asked by At

I went through this Microsoft documentation and trying to resolve the address (Country, State, City) from the geo-coordinates (lat, long):

https://learn.microsoft.com/en-us/dotnet/api/system.device.location.civicaddressresolver?view=netframework-4.8

This is my script which gives me the exact geo-coordinates but unable to resolve the city, country, state from it:

Add-Type -AssemblyName System.Device #Required to access System.Device.Location namespace
$watcher = New-object System.Device.Location.GeoCoordinateWatcher
$watcher.Start()
$watcher.Status #NoData
$watcher.Permission #Granted

while (($watcher.Status -ne 'Ready') -and ($watcher.Permission -ne 'Denied')) {
    Write-Host 'Entering while loop'
    Start-Sleep -Milliseconds 1000 #Wait for discovery.
}
if ($watcher.Permission -eq 'Denied'){
    Write-Host 'Access Denied for Location Information'
} else {


    $location = $watcher.Position.Location
    Write-Host $location # Lat, Long printed - See Output
    $AddressResolver = New-Object System.Device.Location.CivicAddressResolver
    $AddressResolver.ResolveAddress($location) #IsUnknown : True

}

Output:

enter image description here

Any help will be greatly appreciated.

0

There are 0 best solutions below