Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

CivicAddress Class

Represents a civic address. A civic address can include fields such as street address, postal code, state/province, and country or region.

System.Object
  System.Device.Location.CivicAddress

Namespace:  System.Device.Location
Assembly:  System.Device (in System.Device.dll)
public class CivicAddress

The CivicAddress type exposes the following members.

  NameDescription
Public methodCivicAddress()Initializes a new instance of the CivicAddress class.
Public methodCivicAddress(String, String, String, String, String, String, String, String)Initializes a new instance of the CivicAddress class using address information.
Top
  NameDescription
Public propertyAddressLine1Gets or sets the first line of the address.
Public propertyAddressLine2Gets or sets the second line of the address.
Public propertyBuildingGets or sets the building name or number.
Public propertyCityGets or sets the name of the city.
Public propertyCountryRegionGets or sets the country or region of the location.
Public propertyFloorLevelGets or sets the floor level of the location.
Public propertyIsUnknownGets a value that indicates whether the CivicAddress contains data.
Public propertyPostalCodeGets or sets the postal code of the location.
Public propertyStateProvinceGets or sets the state or province of the location.
Top
  NameDescription
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top
  NameDescription
Public fieldStatic memberUnknownRepresents a CivicAddress that contains no data.
Top

A civic address for a location can be obtained from a GeoCoordinate by using a class that implements ICivicAddressResolver.

The CivicAddressResolver class provides a default implementation that returns the civic address that corresponds to a GeoCoordinate, if the location source provides both coordinate data as well as civic address data.

ResolveAddress returns a CivicAddress for the current location. If the location source is unable to resolve the coordinate position to a civic address, Unknown is returned.

The following example shows how to resolve a CivicAddress from a GeoCoordinate location synchronously.

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.");
                }
            }
        }

    }
}

The following example shows how to resolve a CivicAddress from a GeoCoordinate location asynchronously.

using System;
using System.Device.Location;
namespace ResolveAddressSync
{
    class Program
    {
        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.");
            }
        }


    }
}

.NET Framework

Supported in: 4.5.1, 4.5, 4

.NET Framework Client Profile

Supported in: 4

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone 8, Silverlight 8.1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.