我正在寻找一种通过Windows定位API从powershell脚本中收集内部GPS数据的方法,因为Windows定位平台无法再满足需求。以前可以使用com对象。
在Windows 10中是否有实现这一目标的方法?
在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.
}
请确保位置已设置。否则会输出“无法访问位置信息”