Working with Data with the MapPoint Web Service Find APIs
(Page 1 of 4 )
In this second part of a five-part series on MapPoint's Find Service, you will learn how to handle data sources and queries. It is excerpted from chapter six of the book
Programming MapPoint in .NET, written by Chandu Thota (O'Reilly; ISBN: 0596009062). Copyright © 2007 O'Reilly Media, Inc. All rights reserved. Used with permission from the publisher. Available from booksellers or direct from O'Reilly Media.
Data Sources and Countries/Regions
Just as each data source in MapPoint Web Service supports different entity types, there is country/region level mapping to each MapPoint data source. The geographic extent (or the geographic coverage) of each data source is predefined by MapPoint Web Service. For example, the data source MapPoint.NA has a geographic extent of the United States, Canada, Mexico, and Puerto Rico. In the same way, other data sources have different supported country listings. You don’t need to remember which data source needs to be used for each country name—you can use the CommonServiceSoap class for this purpose as well.
Countries/Regions and Their Entity IDs
Before we get into the details of how to query data source geographic extents and how to map a country to a supported data source programmatically, you need to understand how the countries/regions are managed in MapPoint Web Service Data sources. Each country/region is given an entity ID, which is a unique integer number. Each country/region also holds an ISO2- and ISO3-compatible code associated with that country. All of this information is represented as the CountryRegionInfoobject, which exposes several properties, such asEntityID,FriendlyName,Iso2,Iso3, andOfficialName. If you take the United States, for example, the country region information is organized as follows:
Entity ID 244
FriendlyName United States
Iso2 US
Iso3 USA
OfficialName United States of America
An instance of theCountryRegionInfoclass that represents a valid country/region also includes the centroid latitude/longitude of the country. The entity ID for the United States is 244, and it does not change across different versions of the MapPoint Web Service, so you can safely hardcode this ID into your applications for any United States–specific find queries.
To get the country/region information using MapPoint Web Service, use theCommonServiceSoap.GetCountryRegionInfomethod:
//Create Common Service SOAP Class instance
CommonServiceSoap commonsoap = new CommonServiceSoap();
//Assign credentials
. . .
//Get country region info
CountryRegionInfo[] countryregioninfos =
commonsoap.GetCountryRegionInfo(null);
//Do some processing
foreach(CountryRegionInfo crinfo in countryregioninfos)
{
. . .
}
TheGetCountryRegionInfomethod takes an array of entity IDs as integers; however, in the previous code example, I’m passingnullin order to get country/region information for all the countries listed in MapPoint Web Service. Similarly, if you want only country/region information for the United States, your call would look like this with 244 entity ID as an input argument:
//Get country region info
CountryRegionInfo[] countryregioninfos =
commonsoap.GetCountryRegionInfo(new int[] {244});
You get only oneCountryRegionInfoobject (that corresponds to the United States) back from this method.
Note that since the list of county/region information does not change that frequently, it is good idea to store it in an in-memory data structure (such as aHashtablewith the entity ID as the key) in your applications to avoid round trips to the MapPoint Web Service.
Next: Querying for Geographic Extent for a Data Source >>
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.
|
|