使用 Windows 位置服务进行反向地理编码的 PowerShell 脚本

问题描述

我浏览了这个 Microsoft 文档并尝试从地理坐标(纬度、经度)解析地址(国家、州、城市):

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

这是我的脚本,它为我提供了确切的地理坐标,但无法从中解析出城市、国家/地区:

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 @R_441_4045@ion'
} 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

}

输出

enter image description here

任何帮助将不胜感激。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)