Как запросить широту и долготу устройства Windows 10 в PowerShell?
Я ищу способ запросить службу определения местоположения Windows 10 через PowerShell, чтобы вернуть текущую широту и долготу устройства в десятичной записи. Писать изhttp://www.verboon.info/2013/10/powershell-script-get-computergeolocation/ Я собрал следующую функцию:
function Get-LatLong()
{
# Windows Location API
$mylocation = new-object -ComObject LocationDisp.LatLongReportFactory
# Get Status
$mylocationstatus = $mylocation.status
if ($mylocationstatus -eq "4")
{
# Windows Location Status Returns 4, so we're "Running"
# Get latitude and longitude from LatLongReport property
$latitude = $mylocation.LatLongReport.Latitude
$longitude = $mylocation.LatLongReport.Longitude
if ($latitude -ne $null -or $longitude -ne $null)
{
write-host "$longtitude $latitude"
}
Else
{
write-warning "Latitude or Longitude data missing"
}
}
Else
{
switch($mylocationstatus)
{
# All possible status property values as defined here:
# http://msdn.microsoft.com/en-us/library/windows/desktop/dd317716(v=vs.85).aspx
0 {$mylocationstatuserr = "Report not supported"}
1 {$mylocationstatuserr = "Error"}
2 {$mylocationstatuserr = "Access denied"}
3 {$mylocationstatuserr = "Initializing" }
4 {$mylocationstatuserr = "Running"}
}
If ($mylocationstatus -eq "3")
{
write-host "Windows Loction platform is $mylocationstatuserr"
sleep 5
Get-LatLong
}
Else
{
write-warning "Windows Location platform: Status:$mylocationstatuserr"
}
}
} # end function
Когда я вызываю функцию, она возвращает:
PS C: \ windows \ system32> Get-LatLong
ВНИМАНИЕ: Платформа Windows Location: Статус: Отчет не поддерживается
Службы определения местоположения включены на устройстве. Я использую PowerShell от имени администратора. Поиск в интернете не помог.