gpt4 book ai didi

windows - 如何在PowerShell中查询Windows 10设备的经纬度?

转载 作者:可可西里 更新时间:2023-11-01 09:28:17 28 4
gpt4 key购买 nike

我正在寻找一种通过 PowerShell 查询 Windows 10 位置服务的方法,以十进制形式返回设备的当前纬度和经度。从 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

WARNING: Windows Location platform: Status:Report not supported

设备上启用了定位服务。我以管理员身份运行 PowerShell。网络搜索没有帮助。

最佳答案

如果按照代码中的注释: https://msdn.microsoft.com/en-us/library/windows/desktop/dd317716(v=vs.85).aspx

它提到:

[The Location API object model is available for use in the operating systems specified in the Requirements section. It may be altered or unavailable in subsequent versions. Instead, to access location from a website, use the W3C Geolocation API. To access location from a desktop application, use the Windows.Devices.Geolocation API.]

并且支持的平台是:

Minimum supported client Windows 7 [desktop apps only]

结论:

我认为如何在 Windows 10 上查询位置数据的答案是使用 Geolocation API .

关于windows - 如何在PowerShell中查询Windows 10设备的经纬度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36144271/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com