PowerShell:在Windows 10中获取GPS坐标 - 使用Windows位置API?

9
我正在寻找一种通过Windows定位API从powershell脚本中收集内部GPS数据的方法,因为Windows定位平台无法再满足需求。以前可以使用com对象。
在Windows 10中是否有实现这一目标的方法?

更多解决方案请点击此处 - eadmaster
2个回答

21

使用 System.Device.Location 方法的示例,这应该是您正在寻找的。

Add-Type -AssemblyName System.Device #Required to access System.Device.Location namespace
$GeoWatcher = New-Object System.Device.Location.GeoCoordinateWatcher #Create the required object
$GeoWatcher.Start() #Begin resolving current locaton

while (($GeoWatcher.Status -ne 'Ready') -and ($GeoWatcher.Permission -ne 'Denied')) {
    Start-Sleep -Milliseconds 100 #Wait for discovery.
}  

if ($GeoWatcher.Permission -eq 'Denied'){
    Write-Error 'Access Denied for Location Information'
} else {
    $GeoWatcher.Position.Location | Select Latitude,Longitude #Select the relevent results.
}

尝试过了,它可以工作(没有“访问被拒绝”的提示)。但是它给出了完全错误的位置。 - G.Vanem

0

请确保位置已设置。否则会输出“无法访问位置信息”


3
目前你的回答不够清晰。请编辑并添加更多细节,以帮助其他人理解它如何回答所提出的问题。你可以在帮助中心找到有关如何撰写好答案的更多信息。 - Community

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接