ICivicAddressResolver.ResolveAddressCompleted 事件
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
在使用 ResolveAddressAsync(GeoCoordinate) 将纬度/经度解析为市政地址的异步请求完成时发生。
public:
event EventHandler<System::Device::Location::ResolveAddressCompletedEventArgs ^> ^ ResolveAddressCompleted;
event EventHandler<System.Device.Location.ResolveAddressCompletedEventArgs> ResolveAddressCompleted;
member this.ResolveAddressCompleted : EventHandler<System.Device.Location.ResolveAddressCompletedEventArgs>
Event ResolveAddressCompleted As EventHandler(Of ResolveAddressCompletedEventArgs)
事件类型
示例
以下示例演示如何调用 ResolveAddressAsync 和处理 ResolveAddressCompleted 事件。
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.");
}
}
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