Powershell: Getting GPS Coordinates in Windows 10 - Using Windows Location API?

落花浮王杯 提交于 2019-12-21 05:41:24

问题


I'm looking for a way to gather internal GPS data from a powershell script using Windows Location API, as the Windows Location Platform is no longer able to satisfy the need. Previously, there was a com object to use.

Is there a way for this to be accomplished in Windows 10?


回答1:


An example of using the System.Device.Location method, this should be what you're looking for.

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


来源:https://stackoverflow.com/questions/46287792/powershell-getting-gps-coordinates-in-windows-10-using-windows-location-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!