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

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

问题描述:

我正在寻找一种方法来使用Windows位置API从PowerShell脚本收集内部GPS数据,因为Windows位置平台不再能够满足需求。以前,有一个com对象可以使用。Powershell:在Windows 10中获取GPS坐标 - 使用Windows位置API?

有没有办法在Windows 10中完成这项工作?

使用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. 
}