【问题标题】:Powershell: Getting GPS Coordinates in Windows 10 - Using Windows Location API?Powershell:在 Windows 10 中获取 GPS 坐标 - 使用 Windows 位置 API?
【发布时间】:2018-02-27 11:49:07
【问题描述】:
我正在寻找一种使用 Windows 定位 API 从 powershell 脚本收集内部 GPS 数据的方法,因为 Windows 定位平台不再能够满足需求。以前,有一个 com 对象可供使用。
有没有办法在 Windows 10 中实现这一点?
【问题讨论】:
标签:
powershell
geolocation
gps
windows-10
windows-locationapi
【解决方案1】:
一个使用System.Device.Location方法的例子,这应该是你要找的。p>
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.
}