如何解析GEO位置命令输出?

发布于 2025-01-25 08:23:04 字数 1079 浏览 2 评论 0原文

我具有以下功能,可以使您的纬度和经度达到纬度和经度。

function Get-GeoLocation{
    try {
    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.
    }
    }
    # Write Error is just for troubleshooting
    catch {Write-Error "No coordinates found" 
    return "No Coordinates found"
    -ErrorAction SilentlyContinue
    } 

}

$GL = Get-GeoLocation

它将输出类似于您在下面看到的内容:

 Latitude  Longitude
 --------  ---------
55.500729 -55.059044

如何以最有效的方式解析此通讯以将纬度和经度加载到自己的变量中?

I have the following function that will get your latitude and longitude.

function Get-GeoLocation{
    try {
    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.
    }
    }
    # Write Error is just for troubleshooting
    catch {Write-Error "No coordinates found" 
    return "No Coordinates found"
    -ErrorAction SilentlyContinue
    } 

}

$GL = Get-GeoLocation

It will output something similar to what you see below:

 Latitude  Longitude
 --------  ---------
55.500729 -55.059044

How can I parse this commmand in the most efficient way in order to load the latitude and longitude into their own variables?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文