I went through this Microsoft documentation and trying to resolve the address (Country, State, City) from the geo-coordinates (lat, long):
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:
Any help will be greatly appreciated.