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
參數解析的公民位址會由傳遞至事件處理程式的對象成員ResolveAddressCompletedEventArgs傳Address回。