Partager via


CivicAddressResolver.ResolveAddressAsync(GeoCoordinate) Méthode

Définition

Résout une adresse de manière asynchrone à partir d’un emplacement basé sur une latitude et une longitude. L’appel ne bloque pas l’exécution du thread appelant pendant que l’adresse est résolue.

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)

Paramètres

coordinate
GeoCoordinate

GeoCoordinate contenant la localisation à convertir en adresse postale.

Implémente

Exceptions

coordinate a la valeur null.

coordinate ne contient pas de latitude et de longitude valides.

Exemples

Le programme suivant montre comment appeler ResolveAddressAsync pour résoudre une adresse civique de manière asynchrone.

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

Remarques

Cette méthode stocke dans la tâche toutes les exceptions de non-utilisation que l’équivalent synchrone de la méthode peut lever. Si une exception est stockée dans la tâche retournée, cette exception sera levée lorsque la tâche est attendue. Les exceptions d’utilisation, telles que ArgumentException, sont toujours levées de manière synchrone. Pour connaître les exceptions stockées, consultez les exceptions levées par ResolveAddress(GeoCoordinate).

S’applique à