Powershell:获取 Windows 中的 GPS 坐标 10 - 使用 Windows 位置 API?
Powershell: Getting GPS Coordinates in Windows 10 - Using Windows Location API?
我正在寻找一种使用 Windows 位置 API 从 powershell 脚本收集内部 GPS 数据的方法,因为 Windows 位置平台不再能够满足需要。之前有一个com对象可以使用。
有没有办法在 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.
}
确保定位功能已开启。否则它输出 'Access Denied for Location Information'
我正在寻找一种使用 Windows 位置 API 从 powershell 脚本收集内部 GPS 数据的方法,因为 Windows 位置平台不再能够满足需要。之前有一个com对象可以使用。
有没有办法在 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.
}
确保定位功能已开启。否则它输出 'Access Denied for Location Information'