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

jam*_*rro 3 powershell gps geolocation windows-10 windows-locationapi

我正在寻找一种使用Windows Location API从Powershell脚本收集内部GPS数据的方法,因为Windows Location Platform不再能够满足需求。以前,有一个com对象要使用。

在Windows 10中有没有办法做到这一点?

col*_*lsw 8

使用该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.
}
Run Code Online (Sandbox Code Playgroud)