Finding Locations with the MapPoint Web Service Find APIs - Finding Addresses
(Page 2 of 4 )
While the FindServiceSoap.Find method works well for finding places and geographic entities in general, it doesn’t offer any help to find addresses; use the FindServiceSoap.FindAddress method for that purpose.
Like any FindServiceSoap.Find method, the FindServiceSoap.FindAddress method takes a specification object of type FindAddressSpecification and inputs a data

Figure 6-2. MapPoint Web Service data source browser
source name field of type String and an Options field of type FindOptions as input fields to expose an InputAddress field of type Address . Table 6-3 shows the fields exposed on the FindAddressSpecification object.
Table 6-3. Fields exposed in the FindAddressSpecification class
| Field | Description |
| DataSourceName | A string representing the name of the data source in which to search for the address. Example: MapPoint.NA . |
| InputAddress | The input address to be found. This field is of type Address class. |
| Options | The search options ( FindOptions object), which include the range of results, the threshold score of results returned, and a flag to identify which objects are desired in the returned results. |
To use a data source to find addresses, it must have the CanFindAddress capability. An address in MapPoint Web Service is always represented as a valid instance of the Address object; the Address class provides fields such as AddressLine , PrimaryCity , SecondaryCity , Subdivision , PostalCode , and CountryRegion to represent a valid address for all countries/regions. When used as input, the address line information of an address is optional. When an address is returned as an output, the address object also provides a formatted address string via the FormattedAddress field.
Say you want to find the following address:
1 Microsoft Wa y
Redmond, WA 98052
US
First, you need to create an Address object:
//Create an address object
//And assign address values
Address address = new Address();
address.AddressLine = "1 Microsoft Way";
address.PrimaryCity = "Redmond";
address.Subdivision = "WA";
address.PostalCode = "98052";
address.CountryRegion = "US";
Once the Address object is ready, you can find the address information (such as latitude/longitude, best map view information, etc.) using the FindServiceSoap.FindAddress method:
//Create a find address specification object
FindAddressSpecification findAddressSpec = new FindAddressSpecification();
//Assign input address
findAddressSpec.InputAddress = address;
findAddressSpec.DataSourceName = "MapPoint.NA";
//Call the find address method
FindResults foundAddressResults =
findService.FindAddress(findAddressSpec);
//Process found results
if (foundAddressResults.NumberFound > 0)
{
if(foundAddressResults.Results[0].FoundLocation.LatLong != null)
{
//Process latitude/longitude information
. . .
}
}
The previous code snippet assumes that you have the FindService object available with proper credentials assigned.
The FindAddressSpecification also exposes the Options field so that you can control the behavior of the locations returned by this method using the FindOptions class; the FindOptions behavior that we have looked at in the Find method still holds true for this method except that you can only get a maximum of 100 results instead of 500.
Next: Finding Points of Interest Around a Location >>
More BrainDump Articles
More By O'Reilly Media
|
This article is excerpted from chapter six of the book Programming MapPoint in .NET, written by Chandu Thota (O'Reilly; ISBN: 0596009062). Check it out today at your favorite bookstore. Buy this book now.
|
|