CivicAddress 类

定义

表示市政地址。Represents a civic address. 一个市政地址可以包括街道地址、邮政编码、省/直辖市/自治区和国家/地区等字段。A civic address can include fields such as street address, postal code, state/province, and country or region.

public ref class CivicAddress
public class CivicAddress
type CivicAddress = class
Public Class CivicAddress
继承
CivicAddress

示例

下面的示例演示如何以同步方式 CivicAddressGeoCoordinate 位置解析。The following example shows how to resolve a CivicAddress from a GeoCoordinate location synchronously.

using System;
using System.Device.Location;
namespace ResolveAddressSync
{
    class Program
    {
        static void Main(string[] args)
        {
            ResolveAddressSync();
        }
        static void ResolveAddressSync()
        {
            GeoCoordinateWatcher watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.High);
            watcher.MovementThreshold = 1.0; // set to one meter
            watcher.TryStart(false, TimeSpan.FromMilliseconds(1000));

            CivicAddressResolver resolver = new CivicAddressResolver();

            if (watcher.Position.Location.IsUnknown == false)
            {
                CivicAddress address = resolver.ResolveAddress(watcher.Position.Location);

                if (!address.IsUnknown)
                {
                    Console.WriteLine("Country: {0}, Zip: {1}",
                            address.CountryRegion,
                            address.PostalCode);
                }
                else
                {
                    Console.WriteLine("Address unknown.");
                }
            }
        }
    }
}
Imports System.Device.Location

Module ResolveAddressSync

    Public Sub ResolveAddressSync()
        Dim watcher As GeoCoordinateWatcher
        watcher = New System.Device.Location.GeoCoordinateWatcher(GeoPositionAccuracy.High)
        Dim started As Boolean = False
        watcher.MovementThreshold = 1.0     'set to one meter
        started = watcher.TryStart(False, TimeSpan.FromMilliseconds(1000))

        Dim resolver As CivicAddressResolver = New CivicAddressResolver()
        If started Then
            If Not watcher.Position.Location.IsUnknown Then
                Dim address As CivicAddress = resolver.ResolveAddress(watcher.Position.Location)
                If Not address.IsUnknown Then
                    Console.WriteLine("Country: {0}, Zip: {1}",
                                address.CountryRegion,
                                address.PostalCode)
                Else
                    Console.WriteLine("Address unknown.")
                End If
            End If
        Else
            Console.WriteLine("GeoCoordinateWatcher timed out on start.")
        End If
    End Sub


    Public Sub Main()

        ResolveAddressSync()
        Console.WriteLine("Enter any key to quit.")
        Console.ReadLine()
    End Sub

End Module

下面的示例演示如何以异步方式 CivicAddressGeoCoordinate 位置解析。The following example shows how to resolve a CivicAddress from a GeoCoordinate location asynchronously.

using System;
using System.Device.Location;
namespace ResolveAddressSync
{
    class Program
    {
        public static void Main(string[] args)
        {
            ResolveAddressAsync();
        }
        static void ResolveAddressAsync()
        {
            GeoCoordinateWatcher watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.High);
            bool started = false;
            watcher.MovementThreshold = 1.0; // set to one meter
            started = watcher.TryStart(false, TimeSpan.FromMilliseconds(1000));

            if (started)
            {
                CivicAddressResolver resolver = new CivicAddressResolver();

                resolver.ResolveAddressCompleted += new EventHandler<ResolveAddressCompletedEventArgs>(resolver_ResolveAddressCompleted);

                if (watcher.Position.Location.IsUnknown == false)
                {
                    resolver.ResolveAddressAsync(watcher.Position.Location);
                }
            }
        }

        static void resolver_ResolveAddressCompleted(object sender, ResolveAddressCompletedEventArgs e)
        {
            if (!e.Address.IsUnknown)
            {
                Console.WriteLine("Country: {0}, Zip: {1}",
                           e.Address.CountryRegion,
                           e.Address.PostalCode);
            }
            else
            {
                Console.WriteLine("Unknown address.");
            }
        }

    }
}
Imports System.Device.Location

Module ResolveCivicAddressAsync

    Public Sub ResolveCivicAddressAsync()
        Dim watcher As GeoCoordinateWatcher
        watcher = New System.Device.Location.GeoCoordinateWatcher(GeoPositionAccuracy.High)
        Dim started As Boolean = False
        watcher.MovementThreshold = 1.0     'set to one meter
        started = watcher.TryStart(False, TimeSpan.FromMilliseconds(1000))
        If started Then
            Dim resolver As CivicAddressResolver = New CivicAddressResolver()
            AddHandler resolver.ResolveAddressCompleted, AddressOf resolver_ResolveAddressCompleted
            If Not watcher.Position.Location.IsUnknown Then
                resolver.ResolveAddressAsync(watcher.Position.Location)
            End If
        End If

        watcher.Start()

    End Sub

    Sub resolver_ResolveAddressCompleted(ByVal sender As Object, ByVal e As ResolveAddressCompletedEventArgs)
        If Not e.Address.IsUnknown Then
            Console.WriteLine("Country: {0}, Zip: {1}",
                           e.Address.CountryRegion,
                           e.Address.PostalCode)
        Else
            Console.WriteLine("Unknown address.")
        End If
    End Sub


    Public Sub Main()

        ResolveCivicAddressAsync()
        Console.WriteLine("Enter any key to quit.")
        Console.ReadLine()
    End Sub

End Module

注解

GeoCoordinate通过使用实现的类,可以从获取位置的市政地址 ICivicAddressResolverA civic address for a location can be obtained from a GeoCoordinate by using a class that implements ICivicAddressResolver.

CivicAddressResolver GeoCoordinate 如果 location 源同时提供坐标数据和市政地址数据,则类提供一个默认实现,该实现返回与对应的市政地址。The CivicAddressResolver class provides a default implementation that returns the civic address that corresponds to a GeoCoordinate, if the location source provides both coordinate data as well as civic address data.

ResolveAddress 返回 CivicAddress 当前位置的。ResolveAddress returns a CivicAddress for the current location. 如果 location 源无法将坐标位置解析为市政地址, Unknown 则返回。If the location source is unable to resolve the coordinate position to a civic address, Unknown is returned.

构造函数

CivicAddress()

初始化 CivicAddress 类的新实例。Initializes a new instance of the CivicAddress class.

CivicAddress(String, String, String, String, String, String, String, String)

使用地址信息初始化 CivicAddress 类的新实例。Initializes a new instance of the CivicAddress class using address information.

字段

Unknown

表示一个不包含任何数据的 CivicAddressRepresents a CivicAddress that contains no data.

属性

AddressLine1

获取或设置第一行地址。Gets or sets the first line of the address.

AddressLine2

获取或设置第二行地址。Gets or sets the second line of the address.

Building

获取或设置大楼名称或楼号。Gets or sets the building name or number.

City

获取或设置城市名称。Gets or sets the name of the city.

CountryRegion

获取或设置位置所在的国家/地区。Gets or sets the country or region of the location.

FloorLevel

获取或设置位置所在的楼层。Gets or sets the floor level of the location.

IsUnknown

获取一个值,该值指示 CivicAddress 是否包含数据。Gets a value that indicates whether the CivicAddress contains data.

PostalCode

获取或设置位置的邮政编码。Gets or sets the postal code of the location.

StateProvince

获取或设置位置所在的省/直辖市/自治区。Gets or sets the state or province of the location.

方法

Equals(Object)

确定指定对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(继承自 Object)

适用于