Compartir vía


CivicAddressResolver.ResolveAddressAsync(GeoCoordinate) Método

Definición

Resuelve una dirección de forma asincrónica desde una ubicación basada en latitud y longitud. La llamada no bloquea ejecución del subproceso que realiza la llamada mientras se resuelve la dirección.

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)

Parámetros

coordinate
GeoCoordinate

GeoCoordinate que contiene la ubicación que se va a resolver como una dirección de una ciudad.

Implementaciones

Excepciones

coordinate es null.

coordinate no contiene una latitud y longitud válidas.

Ejemplos

En el siguiente programa se muestra cómo llamar ResolveAddressAsync a para resolver una dirección civil de forma asincrónica.

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

Comentarios

Este método almacena en la tarea que devuelve todas las excepciones que no son de uso que puede producir el homólogo sincrónico del método. Si se almacena una excepción en la tarea devuelta, esa excepción se producirá cuando se espere a la tarea. Las excepciones de uso, como ArgumentException, se siguen produciendo de forma sincrónica. Para ver las excepciones almacenadas, vea las excepciones producidas por ResolveAddress(GeoCoordinate).

Se aplica a