CivicAddressResolver.ResolveAddress(GeoCoordinate) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
同步地从基于纬度和经度的位置解析市政地址。 正在解析地址时,此调用将阻止执行线程调用。
public:
virtual System::Device::Location::CivicAddress ^ ResolveAddress(System::Device::Location::GeoCoordinate ^ coordinate);
public System.Device.Location.CivicAddress ResolveAddress (System.Device.Location.GeoCoordinate coordinate);
abstract member ResolveAddress : System.Device.Location.GeoCoordinate -> System.Device.Location.CivicAddress
override this.ResolveAddress : System.Device.Location.GeoCoordinate -> System.Device.Location.CivicAddress
Public Function ResolveAddress (coordinate As GeoCoordinate) As CivicAddress
参数
- coordinate
- GeoCoordinate
GeoCoordinate,它含有要解析为市镇地址的位置。
返回
从 coordinate
参数解析得出的市政地址。 如果无法解析地址,则返回 Unknown。
实现
例外
coordinate
为 null
。
coordinate
不包含有效纬度和经度。
示例
以下程序演示如何调用 ResolveAddress 以同步解析市政地址。
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
注解
地址 ResolveAddressCompleted 解析操作完成时引发 事件。 从 coordinate
参数解析的市政地址由 Address 传递给事件处理程序的对象 ResolveAddressCompletedEventArgs 的成员返回。