Parsing Addresses and More with the MapPoint Web Service Find APIs - Applying Proper Metadata for Faster Searches
(Page 5 of 5 )
Whenever possible, try to apply proper metadata for your find queries, including applying proper entity type information and adding search contexts. For example, if you are searching for Redmond, WA in the United States, you can improve your application’s performance by adding the entity type information of PopulatedPlace (using the entity type name for cities means that you are looking only for a city) and a context of 244 (the entity ID of the United States narrows your search to the United States) during your find call:
//Create a find specifications object
FindSepcification findspecification = new FindSepcification();
//Assign the EntityTypeNames value
findspecification.EntityTypeNames = new string[] {"PopulatedPlace"};
//Assign search context findspecification.Options = new FindOptions();
//Add context for United States
findspecification.Options.SearchContext = 244;
Use Asynchronous Programming Patterns
Since any web service call involves a network round-trip, using asynchronous programming improves the user’s experience dramatically. With MapPoint Web Service Find Service, you can use asynchronous programming paradigms provided by Microsoft .NET Framework. If you are building a web or Windows application using MapPoint Web Service, you can use the MapPoint Web Service asynchronous methods to perform tasks such as Find or FindAddress; however, in order to use asynchronous methods, you use the Begin and End pair methods instead of the actual method itself. For example, to call the Find method in asynchronous patterns, use the BeginFind and EndFindmethods, which internally use theSoapHttpClientProtocolobject’sBeginInvokeandEndInvokemethods.
When you are building an enterprise-level application using MaPoint Web Service, obviously performance is not the only thing you need to keep in mind; you also need to think about supporting multiple languages and cultures, so globalizing your applications to support local languages is an essential part of your application. In the next section, let's see how to leverage some of the MapPoint Web Service features to build global applications.
Globalizing Find
MapPoint Web Service currently supports 10 different languages, meaning that when you use the Find Service with a desired (and supported) language, the Find results are returned in that language. It is important to note that in the case of the Find service, only city names and other entity information are localized to display in that specific language.
Table 6-10 shows the list of languages currently supported in MapPoint Web Service:
Table 6-10. Languages supported in MapPoint Web Service
| Language | Language Code | Lcid |
|---|
| Dutch | nl | 19 |
| English | en | 9 |
| English-United States | en-us | 1033 |
| French | fr | 12 |
| German | de | 7 |
| Italian | it | 16 |
| Portuguese | pt | 22 |
| Spanish | es | 10 |
| Swedish | sv | 29 |
The data sourcesMapPoint.MoonandMapPoint.Worldsupport all of these languages as well as Japanese (language code ja and LCID 1041).
To send your desired language information to the MapPoint Web Service during your Find Service calls, MapPoint Web Service provides SOAP Headers. With Find Service, these settings use theFindServiceSoap.UserInfoFindHeaderValuefield. TheUserInfoFindHeaderValueis of typeUserInfoFindHeader, and it and provides fields to set values for the location search context (theUserInfoFindHeader.Contextfield), user preferred culture (theUserInfoFindHeader.Culturefield), and default distance unit as eithermilesorkilometers(theUserInfoFindHeader.DefaultDistanceUnit field). To use Find Service with a search context for Canada (whose country entity ID is 39) with a preferred language of French (name fr), you would have to provide the user information header to theFindServiceSoap:
//Create a find service soap object
FindServiceSoap findService = new FindServiceSoap();
//Create a user header
UserInfoFindHeader userInfoFindHeader = new UserInfoFindHeader();
//Set the country context to Canada
userInfoFindHeader.Context = new CountryRegionContext();
userInfoFindHeader.Context.EntityID = 39;
//Set the language preference
userInfoRenderHeader.Culture = new CultureInfo();
userInfoRenderHeader.Culture.Name = "fr";
//Then assign the header to the find service proxy
findService.UserInfoFindHeaderValue = userInfoFindHeader;
The entity ID and language name are assigned to the find header before making any find calls. To set the desired culture information, you could also use theLcidID for French instead of using the language name. One thing to remember while using the user information header to obtain localized information from Find Service is that the addresses returned by theFindServiceSoap.FindAddressmethod are never localized.
Where Are We?
Find Service is one of the core components of the MapPoint Web Service, providing many features such as finding places, addresses, and points of interest around a given location. Find Service also provides a way to convert any latitude/longitude information to an entity that contains the geographic information about that given point; it also provides necessary tools to parse addresses to see whether a given string is a place or an address so that you can call the appropriate method to find information.
Since Find Service methods are web service methods, it is important to think about performance optimization and asynchronous programming patters where applicable. Finally, Find Service also provides a way to get information in a specific localized language (among the 10 supported languages).
In the next chapter, we’ll look at MapPoint Web Service Route and Render Service components.
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
|
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.
|
|