CivicAddressResolver.ResolveAddressAsync(GeoCoordinate) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
以非同步的方式解析根據緯度和經度之位置的地址。 在解析地址的時候,該呼叫不會封鎖呼叫執行緒的執行。
public:
virtual void ResolveAddressAsync(System::Device::Location::GeoCoordinate ^ coordinate);
public void ResolveAddressAsync (System.Device.Location.GeoCoordinate coordinate);
abstract member ResolveAddressAsync : System.Device.Location.GeoCoordinate -> unit
override this.ResolveAddressAsync : System.Device.Location.GeoCoordinate -> unit
Public Sub ResolveAddressAsync (coordinate As GeoCoordinate)
參數
- coordinate
- GeoCoordinate
GeoCoordinate 包含解析到市鎮地址的位置。
實作
例外狀況
coordinate
為 null
。
coordinate
未包含有效的緯度和經度。
範例
下列程式示範如何呼叫 ResolveAddressAsync 以異步方式解析公民位址。
using System;
using System.Device.Location;
namespace ResolveAddressSync
{
class AsyncProgram
{
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
備註
這個方法會儲存在工作中,它會傳回方法同步對應專案可以擲回的所有非使用例外狀況。 如果例外狀況儲存在傳回的工作中,則會在等候工作時擲回該例外狀況。 使用例外狀況,例如 ArgumentException仍會同步擲回。 如需預存例外狀況,請參閱 擲回的 ResolveAddress(GeoCoordinate)例外狀況。