Working with Data with the MapPoint Web Service Find APIs - Working with Find Methods
(Page 3 of 4 )
MapPoint Web Service Find Service is programmatically exposed as part of the FindServiceSoap class, which has many find methods including Find, FindAddress, FindNearby, andFindById. Choose an appropriate find method based on your application’s requirements. In this section, let’s look in detail at each find method offered by the MapPoint Web Service Find Service.
Finding Places
To find geographic entities and places by their names, use the FindServiceSoap.Find method. This method takes the FindSpecificationas an input argument and returns theFindResultsobject as a return value. TheFindSpecificationwraps several values, including the input place name as a string, the data source to be used for searching the place, and an array of entity type names to find. Table 6-2 shows the fields of theFindSpecificationclass.
Table 6-2. Fields of the FindSpecification class
| Field | Description |
| DataSourceName | A string representing the name of the data source in which to search for a place. For example, MapPoint.NA is the data source used for finding places in North America. |
| EntityTypeNames | An array of strings representing the names of the entity types to find. |
| InputPlace | The place name to find. |
| Options | The search options (FindOptionsobject), which includes the range of results, the threshold score of results returned, the search context, and a flag to identify which objects are desired in the returned results. |
The data source used for theFindmethod must have theCanFindPlacescapability. TheFindResultsreturn value indicates the number of matches for the input place query using theFindResults.NumberFoundfield; when no results match your query, theNumberFoundfield is set to zero. All matches are exposed via the
FindResults.Resultsfield as a collection ofFindResultobjects; eachFindResultobject returned as a match contains aLocationobject that wraps the location information and a score indicating the level of confidence in the match. A validLocationobject provides one or all of the following: address information, entity information, latitude/longitude information, and best map view information.
Next, let’s look at theFindmethod details: the following code shows how the Find API can be used to find all places named Redmond:
//Create find service soap
FindServiceSoap findsoap = new FindServiceSoap();
//Assign credentials
. . .
//Create FindSpecification
FindSpecification findspec = new FindSpecification();
//Assign data source
findspec.DataSourceName = "MapPoint.NA";
//Assign input place to search
findspec.InputPlace = "Redmond";
//Now call find
FindResults findresults = findsoap.Find(findspec);
//Assign found count
foreach(FindResult findresult in findresults.Results)
{
//Display results
. . .
}
With options set at their defaults, this query returns the following seven places named Redmond:
Redmond, Washington, United States
Redmond, Oregon, United States
Redmond, Western Australia, Australia
Redmond, Larimer, Colorado, United States
Redmond, Butler, Pennsylvania, United States
Redmond, Sevier, Utah, United States
Redmond, Mason, West Virginia, United States
Next: Finding more default matches >>
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.
|
|