Skip to main content

Geocode

  • 3 minutes to read

This document describes how to use the geocoding feature in the Map control. This feature allows you to get information about a geographic point on a map.

The document consists of the following sections.

#Overview

The Map control supports the popular Microsoft Bing Geocode service, which provides information associated with the geographic point on a map (an address, postal code, etc.) based on a point's location (latitude and longitude coordinates).

NOTE

The geocode feature should interact with one of the map data providers (Bing Maps or OpenStreetMap) from which the map control obtains map tiles. For more details, see the Lesson 1 - Connect to Bing Mapsor Lesson 2 - Connect to OpenStreetMap tutorials.

The geocode functionality in the Map control is performed by the Bing Geocode data provider. This provider is represented by the BingGeocodeDataProvider object. The section below explains how to use the BingGeocodeDataProvider in the map control.

#Enabling Geocode

To enable geocoding in the Map control, do the following.

  • Create an information layer and add it to the map.

    The information layer is used to present GIS elements above the map. For more information, see Layers.

  • Create an instance of the BingGeocodeDataProvider and assign it to the InformationLayer.DataProvider property.
  • Specify the Bing Maps key via the BingGeocodeDataProvider.BingKey property.

    NOTE

    If you run the application, and see a window with the following error message: ”The specified Bing Maps key is invalid. To create a developer account, refer to http://www.microsoft.com/maps/developers”, refer to the following tutorial: How to: Get a Bing Maps Key.

The code snippet below shows how this can be done.

When the Map control is connected to the Bing Geocode service, you can obtain information about a geographic point in the pushpin's tooltip. To do this, do the following.

The image below shows how this works for the "Kennedyville" location.

BingMapsGeocodeProvider_GeocodeResult

You can also use the BingGeocodeDataProvider.MaxVisibleResultCount property to specify how many tooltips should be shown on a map simultaneously.

#Using a Custom UI

The map control allows you obtain additional results (address, name, entity type, etc.) for a specified location from the Bing Geocode service.

NOTE

If you do not want pushpins to be generated on the map by mouse click, set the BingGeocodeDataProvider.ProcessMouseEvents property to false.

To start geocoding for a location, call the BingGeocodeDataProvider.RequestLocationInformation method.

For instance, you have a UI that consists of 2 text boxes named "tbLatitude" and "tbLongitude", and a button named "bRequestLocation". To start a search, click the Request Location button. This calls the RequestLocationInformation method.

The results are stored by the RequestResultBase object's GeocodeRequestResult descendant within the LocationInformationReceivedEventArgs of the BingGeocodeDataProvider.LocationInformationReceived event handler.

The results contain the entity type, address and coordinates associated with the geographic location.

#Geocode Results

To get the geocode results for a specified location, handle the BingGeocodeDataProvider.LocationInformationReceived event. The results are stored by the RequestResultBase object's GeocodeRequestResult descendant within the LocationInformationReceivedEventArgs of the LocationInformationReceived event handler.

The following code snippet shows how to handle the event.

The results for Latitude - "41.27" and Longitude - "-96.05" are shown in the image below.

BingMapsGeocodeDataProvider_CustomGeocode

#Examples

The following examples demonstrate how to use the geocode feature in the map control.

See Also