GeoCoordinate.IsUnknown 属性

定义

获取一个值,该值指示 GeoCoordinate 是否未包含纬度或经度数据。

public:
 property bool IsUnknown { bool get(); };
public bool IsUnknown { get; }
member this.IsUnknown : bool
Public ReadOnly Property IsUnknown As Boolean

属性值

如果 GeoCoordinate 未包含纬度或经度数据,则为 true;否则为 false

示例

下面的代码示例验证与某个位置对应的 是否 GeoCoordinateUnknown 打印出其纬度和经度之前。

using System;
using System.Device.Location;

namespace GetLocationPropertyHandleUnknown
{
    class Program
    {
        static void Main(string[] args)
        {
            GetLocationPropertyHandleUnknown();
        }

        static void GetLocationPropertyHandleUnknown()
        {
            GeoCoordinateWatcher watcher = new GeoCoordinateWatcher();
            watcher.TryStart(false, TimeSpan.FromMilliseconds(1000));

            if (watcher.Position.Location.IsUnknown != true)
            {
                GeoCoordinate coord = watcher.Position.Location;

                Console.WriteLine("Lat: {0}, Long: {1}",
                    coord.Latitude,
                    coord.Longitude);
            }
            else
            {
                Console.WriteLine("Unknown");
            }
        }
    }
}
Imports System.Device.Location

Module GetLocationProperty
    Public Sub GetLocationPropertyHandleUnknown()
        Dim watcher As New System.Device.Location.GeoCoordinateWatcher()
        watcher.TryStart(False, TimeSpan.FromMilliseconds(1000))
        If watcher.Position.Location.IsUnknown <> True Then
            Dim coord As GeoCoordinate = watcher.Position.Location
            Console.WriteLine("Lat: {0}, Long: {1}", coord.Latitude, coord.Longitude)
        Else
            Console.WriteLine("Unknown latitude and longitude.")
        End If
    End Sub

    Public Sub Main()
        GetLocationPropertyHandleUnknown()
        Console.ReadLine()
    End Sub

End Module

注解

GeoCoordinate不包含纬度或经度数据的 等于 Unknown

适用于