Chapter 5. Programming MapPoint Web Service

MapPoint 2004 offers extensive capabilities for building location applications, but you can only develop Windows desktop applications using MapPoint 2004 APIs. Moreover, map data must be available locally for MapPoint 2004 applications to work. If you want to develop applications for web or mobile devices, MapPoint 2004 is obviously not an option. However, if you want to develop location-based applications for web and mobile devices, you are not out of luck—that’s where MapPoint Web Service comes in.

The MapPoint Web Service is a Microsoft-hosted XML web service that is fully compliant with SOAP. The MapPoint Web Service APIs are exposed via the standard Web Service Description Language (WSDL) that can be used to develop applications using any SOAP/XML-aware programming language. Because of that, MapPoint Web Service transcends traditional boundaries to become a platform-agnostic programming tool with which you can develop a variety of location-based applications.

In this chapter, I will explain how the MapPoint Web Service works and how to get started with your development environment. Since the MapPoint Web Service is SOAP protocol-compliant, it is inherently communication protocol-agnostic (working across HTTP, FTP, etc.); however, in this chapter, as well as Chapters 68, I will be using the HTTP protocol as the medium of communication.

Finally, before we get into the full details of MapPoint Web Service programming, I want to remind you that the MapPoint Web Service is a subscription-based web service, which means that you will be charged for the usage of the MapPoint Web Service APIs. I strongly recommend reading the end user license agreement (EULA) for more details on the tarrif and details on how the API calls are charged. Don’t panic—accessing MapPoint Web Service in the staging environment is absolutely free, so you do not need to pay for accessing the APIs.

How Does MapPoint Web Service Work?

Like any other web service, MapPoint Web Service enables you to develop distributed applications. By invoking MapPoint Web Service methods over the wire, you can perform many location-based tasks, such as finding places, finding addresses, calculating driving directions, rendering maps, and so on. All web service requests that invoke MapPoint Web Service methods must be authenticated using the credentials assigned to your MapPoint Web Service account (I will go into more detail on this subject later in the chapter). Once your request is successfully authenticated, MapPoint Web Service executes the corresponding method using your input parameters and returns an appropriate output wrapped in a valid response. While all this communication happens in SOAP, you do not need to get into the details of SOAP request or response to communicate with MapPoint Web Service; Microsoft .NET framework does a great job of abstracting away the wire-format level specifics.

Figure 5-1 shows how your location-enabled applications communicate with MapPoint Web Service.

How MapPoint Web Service works
Figure 5-1. How MapPoint Web Service works

As you can see, any application you develop using MapPoint Web Service is a “connected” application, requiring your application to be able to communicate over the wire via the Internet.

So, what are the advantages of a connected MapPoint Web Service-based application? There are many advantages to this model:

Your applications remain lightweight.

Since location-related data and the core processing remains in the cloud, your applications primarily contain your business-specific location processing.

Location data is maintained for you and is always up-to-date.

Since the location data is also hosted by Microsoft, you don’t need to worry about keeping the location data up-to-date; this task is abstracted from your program seamlessly.

Building global applications is easy.

Since MapPoint Web Service offers location data for multiple countries/regions of the world, you can write only one application and use many location data sources to work with location data from different countries/regions.

Now that you know how your applications communicate with MapPoint Web Service at a macro level, let’s get started programming with MapPoint Web Service.

Getting Started with MapPoint Web Service

In this section, let’s look at a step-by-step approach to getting started with MapPoint Web Service. If you have already signed up for MapPoint Web Service, are waiting to receive your credentials, and can’t wait to start programming with MapPoint Web Service, use the evaluation credentials provided with the companion material; however, remember that these credentials are shared among all readers of this book and may expire at some point in the future.

Requesting MapPoint Web Service Credentials

The first step in programming with MapPoint Web Service is getting your own credentials to access the MapPoint Web Service APIs. Fill in the account request form available on the MapPoint web site at http://www.microsoft.com/mappoint/evaluation/default.aspx. Once you complete and submit the form, you will receive an email containing your MapPoint Web Service account information that includes a user ID and password to access the MapPoint Web Service APIs and another user ID and password to manage your MapPoint Web Service account. Managing your MapPoint Web Service account is done using their Customer Services site, (also known as the Extranet), details of which are included in the email. The customer services site can be considered an administrative console where you can manage your account user IDs and passwords, check your MapPoint Web Service usage (i.e., how many requests you have submitted so far), manage your custom data, and so on. Details on the Customer Services site are discussed later in this chapter.

Tip

It is important to remember that the credentials you receive via email only give you access to the staging version of the MapPoint Web Service. The production version of the MapPoint Web Service is accessible only to the customers who actually sign the MapPoint Web Service contract.

The evaluation credentials you have received in the email are only valid for 45 days; after 60 days, these credentials expire, and your application can no longer communicate with MapPoint Web Service. If you are in still in the development phase at that time, however, you can ask the MapPoint Web Service Support to extend the evaluation period.

Accessing the MapPoint Web Service APIs

Now that you have your own set of MapPoint Web Service credentials, let’s look at how to access the APIs. The formal WSDL document for the MapPoint Web Service APIs can be found at the following locations:

If you are new to the world of web services, WSDL documents are the “contracts” that publish the web service interfaces, methods, and arguments in XML format. WSDL documents also express the types and their wire formats by defining them in XSD simple and complex types.

You might have noticed that MapPoint Web Service offers a staging environment and a production environment; however, the APIs offered by both environments are exactly the same. So why do you need two different environments? The staging environment is primarily targeted for development and testing purposes, while the production environment should be used for live applications. Moreover, the staging and production environments are physically isolated to ensure the Service Level Agreement (SLA) compliance in terms of availability (99.9%) and API response times. For the staging environment, the SLAs are not applicable (the staging Web Service access is free!); however, the SLAs are fully applicable to the production environment. Again, I recommend that you read the EULA for more details on SLAs related to availability and response time.

If you are either prototyping your MapPoint Web Service application or are still in the development phase, you should use the staging environment; once you are done with the development and testing, move your application to production environment. Note that if you are performing large-scale stress testing , it should be scheduled and worked out with the MapPoint operations team in advance. Moving your application is as simple as changing the service URL within your MapPoint Web Service proxy class, which I’ll explain later in this chapter. Finally, MapPoint Web Service APIs are available on both normal (http) and secured (https) channels.

Accessing the Customer Services Site

When you request evaluation credentials to access MapPoint Web Service, you also receive a set of credentials to the Customer Services site, where you can manage your web service account. Figure 5-2 shows the Customer Services site reports page.

Customer Services site
Figure 5-2. Customer Services site

I will discuss managing your custom data later in this chapter.

Preparing Your Development Environment

Now that you know how to get started with MapPoint Web Service, let’s look at how to prepare your development environment to develop MapPoint Web Service applications.

Adding a Web Reference

If you are developing managed code applications using Visual Studio .NET 2003 or later, programming with MapPoint Web Service is fairly straightforward; you can access the MapPoint Web Service by using the Add Web Reference option from the project context menu, as shown in Figure 5-3.

Add Web Reference context menu
Figure 5-3. Add Web Reference context menu

When you see the Add Web Reference dialog window, type the MapPoint Web Service staging service URL in the URL textbox, as shown in Figure 5-4.

Once you type the staging service URL, and the WSDL document is parsed by Visual Studio, the documentation available within the WSDL document is shown in the preview pane. At this point, you can click the Add Reference button to add the MapPoint Web Service as a web reference to your project. When you click on the Add Reference button, Visual Studio .NET automatically creates a proxy class that can be used to program with MapPoint Web Service. By default, this proxy class is named Reference.cs (or Reference.vb) and is placed within the Web References directory created inside the project’s root directory (this file can only be seen when the Show All Files mode is enabled in the Visual Studio .NET solution explorer). The location of the Reference.cs file is shown in Figure 5-5.

Adding MapPoint Web Service staging service as a web reference
Figure 5-4. Adding MapPoint Web Service staging service as a web reference

Tip

If you are developing your applications using VB 6.0/ASP in unmanaged code, you can still use MapPoint Web Service; however, in this case, you need to use either COM Wrappers around the managed code proxy class or the Microsoft SOAP Toolkit.

This class file contains all the C# (or VB.NET) equivalents of the interface definitions in the WSDL document. For example, the MapPoint Web Service WSDL document contains a complex type to represent latitude and longitude:

    <s:complexType name="LatLong">
      <s:sequence>
       <s:element minOccurs="0" maxOccurs="1" default="0" name="Latitude" type="s:double" />
       <s:element minOccurs="0" maxOccurs="1" default="0" name="Longitude" type="s:double" />
     </s:sequence>
   </s:complexType>
Proxy class file added by Visual Studio .NET
Figure 5-5. Proxy class file added by Visual Studio .NET

This type definition is represented as a class in the Reference.cs file:

    public class LatLong {

     /// <remarks/>
     [System.ComponentModel.DefaultValueAttribute(0)]
     public System.Double Latitude = 0;

     /// <remarks/>
     [System.ComponentModel.DefaultValueAttribute(0)]
     public System.Double Longitude = 0;
    }

As you can see, the previous class is a pure programmatic type representation of the XSD type defined in the WSDL document. You can use this type in your applications as you can any other .NET type. Not all the classes in the proxy file (Reference.cs or Reference.vb) are pure type definitions with just structure information like LatLong class; there are also some classes with methods that you can invoke from your application, including CommonServiceSoap, FindServiceSoap, RouteServiceSoap, and RenderServiceSoap, which are derived from the SoapHttpClientProtocol class from the System.Web.Service.Protocols namespace. Each class has a constructor with the service URL hardcoded within it.

If you are not familiar with service URLs , they are the so-called “service endpoints " of a web service that offer remote methods that can be invoked in a distributed environment. For MapPoint Web Service, there are four service endpoints that map to the service class types specified previously. The service URL and service class type mapping are shown in Table 5-1.

Table 5-1. MapPoint web service endpoints

Service name

Class type

Service URL

Common Service

CommonServiceSoap

http://findv3.staging.mappoint.net/Find-30/Common.asmx

Find Service

FindServiceSoap

http://findv3.staging.mappoint.net/Find-30/FindService.asmx

Route Service

RouteServiceSoap

http://routev3.staging.mappoint.net/Route-30/RouteService.asmx

Render Service

RenderServiceSoap

http://renderv3.staging.mappoint.net/Render-30/RenderService.asmx

Each one of the above four types (classes) has a constructor with the service URL hardcoded in the constructor; for example, if you look for the constructor of the FindServiceSoap class in the Reference.cs file, you will find the definition as follows:

    public FindServiceSoap()
    {
      this.Url = "http://findv3.staging.mappoint.net/Find-30/FindService.asmx";
    }

When you invoke any methods on the FindServiceSoap class, a proxy class for the Find Service, you are remotely invoking methods on the MapPoint Web Service servers. However, if you look closely, the previously stated service URL is pointing to the MapPoint Web Service staging servers. When you want your application to work with the MapPoint Web Service production servers, you must change the URL to point to the production WSDL and recompile the application, which can be an issue if you want to switch between the staging and production environments without re-compiling the application each time you switch. However, it has a very simple workaround—just make the service URL configurable.

Static versus dynamic service URL

After adding a web reference using Visual Studio .NET, you can choose whether to make the service URL dynamic, meaning that the proxy classes are generated such that the service URLs can be configured and managed via the config file (web.config for web applications and app.config for Windows applications). The default option is a static service URL. Figure 5-6 shows the web reference property to change the URL’s behavior.

If you look at the FindServiceSoap constructor with the dynamic service URL option, the class constructor looks as follows:

    public FindServiceSoap()
    {
        string urlSetting =
         System.Configuration.ConfigurationSettings.AppSettings["myapp.CommonService"];
        if ((urlSetting != null))
        {
URL behavior setting
Figure 5-6. URL behavior setting
          this.Url = string.Concat(urlSetting, "FindService.asmx");
        }
        else
       {
        this.Url = "http://findv3.staging.mappoint.net/Find-30/FindService.asmx";
       }
    }

The constructor first tries to obtain the service URL from the configuration file, and when it can’t find it in the configuration file, it reassigns the static service URL. It is important to note that only the non-asmx part of the service URL is made configurable, while the asmx (for example, FindService.asmx) filename is still hardcoded. To support this dynamic URL behavior, add the following application key in the configuration file to access staging MapPoint Web Service:

    <appSettings>
      <add key="myapp.CommonService"
        value="http://findv3.staging.mappoint.net/Find-30/"/>
      </appSettings>
    </configuration>

Along similar lines, add the following value to access the production MapPoint Web Service:

    <appSettings>
      <add key="myapp.CommonService"
        value="http://findv3.service.mappoint.net/Find-30/"/>
      </appSettings>
    </configuration>

To enable dynamic service URL behavior, in an ideal world, you would select the Dynamic option for the URL Behavior property from Visual Studio .NET, and you would be all set—except that you aren’t. The dynamic URL feature in Visual Studio .NET does not work for MapPoint Web Service. In Visual Studio .NET, the static/dynamic service URL feature was designed for web services with one service endpoint per WSDL document, which means there is only class that implements SoapHttpClientProtocol type per Reference.cs or Reference.vb file. Even if there is more than one service endpoint, the assumption was that the base URL of the service is always the same; however, for MapPoint Web Service, one WSDL actually points to four services that have three physical service endpoints . So, in order to make your MapPoint Web Service proxy class properly enabled with dynamic URL behavior, you need to do the following steps:

First, add the following key to your configuration file:

    <appSettings>
      <add key="myapp.CommonService"
        value="http://findv3.staging.mappoint.net/Find-30/Common.asmx"/>
      <add key="myapp.FindService"
        value="http://findv3.staging.mappoint.net/Find-30/Find.asmx"/>
      <add key="myapp.RouteService"
        value="http://routev3.staging.mappoint.net/Route-30/Route.asmx"/>
      <add key="myapp.RenderService"
        value="http://renderv3.staging.mappoint.net/Render-30/Render.asmx"/>
    </appSettings>

Next, modify the service soap class constructors as shown below:

CommonServiceSoap class:

    public CommonServiceSoap() {
      string urlSetting =
        System.Configuration.ConfigurationSettings.AppSettings["myapp.CommonService"];
      if ((urlSetting != null)) {
         this.Url = urlSetting;
      }
      else {
          this.Url = "http://findv3.staging.mappoint.net/Find-30/CommonService.asmx";
      }
    }

FindServiceSoap class:

    public FindServiceSoap() {
      string urlSetting =
        System.Configuration.ConfigurationSettings.AppSettings["myapp.FindService"];
      if ((urlSetting != null)) {
        this.Url = urlSetting;
      }
      else {
          this.Url = "http://findv3.staging.mappoint.net/Find-30/FindService.asmx";
      }
    }

RouteServiceSoap class:

    public RouteServiceSoap() {
      string urlSetting =
       System.Configuration.ConfigurationSettings.AppSettings["myapp.RouteService"];
      if ((urlSetting != null)) {
        this.Url = urlSetting;
      }
      else {
          this.Url = "http://routev3.staging.mappoint.net/route-30/RouteService.asmx";
      }
    }

RenderServiceSoap class:

    public RenderServiceSoap() {
      string urlSetting =
       System.Configuration.ConfigurationSettings.AppSettings["myapp.RenderService"];
      if ((urlSetting != null)) {
        this.Url = urlSetting;
      }
      else {
          this.Url =
           "http://renderv3.staging.mappoint.net/render-30/RenderService.asmx";
      }
    }

With this code in place, your application uses the service URL specified in the configuration file; when no configuration setting is found, staging service URLs are used instead.

Before we move to the next section, it is important to note that the modifications that you make to the Reference.cs or Reference.vb file are not persisted when you refresh the web reference. Be careful when you refresh the MapPoint Web Service web reference.

Storing your credentials securely

You need to secure MapPoint Web Service credentials through proper application configuration. MapPoint Web Service is a subscription-based web service, and each of your MapPoint Web Service requests must be authenticated to obtain a valid

response; for this purpose, MapPoint Web Service uses digest authentication. When you make a web service method call, you must assign your credentials to the service class.

For example, if you are invoking the Find method on the FindServiceSoap class, you need to assign your MapPoint Web Service credentials before calling the method:

    //Create service class instance
    FindServiceSoap findservice = new FindServiceSoap();
    //Assign credentials - Do not do this!
    findservice.Credentials =
       new System.Net.NetworkCredential("yourid", "yourpassword");
    //Invoke the method
    findservice.find(...);

In this code, the credentials are assigned using the System.Net.NetworkCredential object by hardcoding the user ID and password. There is a maintenance risk associated with this approach; for security reasons, you are required to change your MapPoint Web Service account password once every 45 to 60 days. When the time comes to change your password, you need to update the password and re-compile. In order to avoid these maintenance headaches, make the user ID and password configurable from a configuration file (app.config or web.config). Storing the user ID and password in clear text in the configuration file may pose a security threat, so you need to store the credentials in the configuration file in encrypted form.

There are multiple ways of encrypting your MapPoint Web Service ID and password. In any case, you must develop an encryption library using either the Data Protection APIs or Encryption APIs . The simplest way, of course, is to use the Windows Data Protection APIs (DPAPI ). The DPAPI support two kinds of entropies : machine store entropy and user store entropy . In both cases, you can also provide private entropy , which adds an additional layer of security.

Tip

For a detailed description of DPAPI and Encryption API programming, along with other security recommendations for online web applications, check out the Microsoft Patterns and Practices Guide online: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetsec/html/SecNetHT07.asp?frame=true.

Since the Data Protection APIs are Win32 APIs, you need to build C# wrappers around them. A sample implementation of the DPAPI is included in the companion material (project Chapter05); the DataProtectionCore sample class can be used for encrypting and decrypting the MapPoint Web Service ID and password. The following code shows how to encrypt any given string using the DataProtectionCore sample class:

    public static string Encrypt(string input)
    {
      Chapter05.EncryptionUtil.DataProtectorCore dp
      = new Chapter05.EncryptionUtil.DataProtectorCore(
          Chapter05.EncryptionUtil.Store.USE_MACHINE_STORE);
       byte[] encryptedBuffer =
           dp.Encrypt(System.Text.ASCIIEncoding.ASCII.GetBytes(input),
                        null);
       return Convert.ToBase64String(encryptedBuffer);
    }

Once the user ID and password are encrypted as shown in the previous code, you can store them in the configuration file as follows:

    <configuration>
      <appSettings>
        <add key="MapPointWebServiceID"
              value="CAAAAAAADZgAAqAAAQ....tYt9br2PpFHM0AXJd/tIJ/bbb74="/>
        <add key="MapPointWebServicePassword"
              value="AQAAANCMnd8BFdE ....HTPITIgU6FQcAXJd/tIJXteE8/wQ=="/>
      </appSettings>
    </configuration>

Now your MapPoint Web Service ID and password are secure in the configuration file; however, your MapPoint Web Service application cannot readily use the encrypted MapPoint Web Service ID and password from the configuration file. You need to write a decrypt routine:

    public static string Decrypt(string input)
    {
       Chapter05.EncryptionUtil.DataProtectorCore dp
       = new Chapter05.EncryptionUtil.DataProtectorCore(
          Chapter05.EncryptionUtil.Store.USE_MACHINE_STORE);
       byte[] decryptedBuffer = dp.Decrypt(Convert.FromBase64String(input)
                         , null);
       return System.Text.Encoding.ASCII.GetString(decryptedBuffer);
    }

In this routine, the input string is decrypted back to the original ASCII text. Once you have this decrypt routine, you can always read the encrypted MapPoint Web Service ID and password, decrypt them, and pass them to the MapPoint Web Service:

    //Create a find service instance
    FindServiceSoap find = new FindServiceSoap();
    //Assign credentials
    find.Credentials = new System.Net.NetworkCredential(
    Decrypt(ConfigurationSettings.AppSettings["MapPointWebServiceID"]),
    Decrypt(ConfigurationSettings.AppSettings["MapPointWebServicePassword"]));
    . . .
    //Find places
    FindResults results = find.Find(spec);

The Encrypt and Decrypt methods are available in the companion material in the Chapter05 class.

Preauthenticate requests for performance gains

Finally, for performance reasons, always assign the PreAuthenticate property on the service SOAP class to True so that your application can avoid any extraneous round-trips to the server just for authentication. For example, on FindServiceSoap service class, set the value as shown:

    findservice.PreAuthenticate = true;

Now that you know how to prepare your development environment for MapPoint Web Service application development, let’s get into the MapPoint Web Service object model before we start programming.

Understanding MapPoint Web Service Object Model

MapPoint Web Service consists of four core services (or engines) that work with an array of map data sources. The core services depend on the data sources for location-oriented tasks, such as finding a place, finding an address, and so on. The data sources provide the necessary data to perform location-based tasks. In MapPoint Web Service, the data sources are organized based on geographic coverage; for example, the data source that contains the map data for all North American regions is MapPoint.NA. Figure 5-7 summarizes this discussion pictorially.

Along with the predefined MapPoint data sources, you can also add your business-specific data as custom data source. With this introduction, let’s look at services and data sources in detail. If you recall from our earlier discussion, MapPoint Web Service consists of four integral service components, including:

  • Common service

  • Find service

    MapPoint Web Service core services
    Figure 5-7. MapPoint Web Service core services
  • Render service

  • Route service

Let’s look at each service in detail to understand more.

Common Service

The common service contains classes, methods, and properties that are common to the other three services (find, route, and render) or are basic utility functions, such as getting the version of the MapPoint Web Service, obtaining data source information, and calculating great circle distance.

This service is programmatically represented by the CommonServiceSoap class.

Find Service

The find service offers core find functionality, such as finding places, addresses, nearby points of interests, latitude/longitude coordinates, and geographic entities (such as parks, airports, and so on).

Some of the find methods only work with MapPoint Web Service data, and a few methods in the find service are designed to work only with your business-specific data (I will discuss this more later).

This service is programmatically represented by the FindServiceSoap class.

Render Service

The render service allows you to render maps of found places or addresses and routes, using your custom business data as pushpins. You can also use it to customize the map visualization, size, label font size, and so on.

This service is programmatically represented by the RenderServiceSoap class.

Route Service

The route service offers methods to calculate driving directions, routes, and route map views. Using this service, you can calculate the driving directions among any given waypoints.

This service is programmatically represented by the RouteServiceSoap class.

I will discuss these core services in detail in Chapters 6, 7, and 8, but for now let’s look at another important concept in programming with MapPoint Web Service: data sources .

MapPoint Web Service Data Sources

Data sources are the essential building blocks on which the MapPoint Web Service functionality largely depends. At a macro level, data sources are simply stores that contain map data, geographic entity information, and point of interest information; this data is made accessible to the MapPoint Web Service via several APIs.

Data sources in MapPoint Web Service can be broadly categorized into two categories: MapPoint data sources and customer data sources. MapPoint data sources are compiled (created), hosted, and maintained by Microsoft; an example would be the geographic coverage map data source for North America, MapPoint.NA. A customer data source contains business specific data (such as Company A’s 40 store locations in North America) compiled and maintained by customers (your company or you) but hosted by MapPoint Web Service. Next, let’s look at each one of these data source types in detail.

MapPoint data sources

MapPoint Web Service makes more than 45 data sources available for you to program with. These 45 data sources can be broadly categorized into three types of data sources:

  • Map data sources

  • Point of interest data sources

  • Icon data sources

Let’s look at each data source type in detail.

Map data sources Map data sources contain the geographic data used to perform location-oriented tasks, such as finding places and addresses, calculating routes, and rendering maps. All these data sources support entities, which represent the physical existing “things” in the real world, such as airports, coffee shops, libraries, roads and so forth. Table 5-2 shows the Map Data Sources available in MapPoint Web Service.

Table 5-2. Data sources and coverage areas

Data source name

Geographic coverage

MapPoint.NA

North America

MapPoint.EU

Europe

MapPoint.BR

Brazil

MapPoint.AP

Asia Pacific

MapPoint.World

World

MapPoint.Moon

Moon

Tip

For a detailed list of entities supported by these data sources, check Microsoft’s online documentation at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/mappointsdk/html/index.asp.

Point of interest data sources MapPoint Web Service provides more than 35 point of interest data sources containing information about millions of businesses and organizations in several countries and regions in Europe and North America. The data contained in these data sources is organized by Standard Industry Code (SIC) and includes properties such as location and contact information. You can use these data sources to find businesses either by searching attributes (such as store names, cities, etc.) or by performing a proximity search around a given latitude and longitude (such as a store-locator).

Almost all point of interest data are provided by external data vendors (such as NavTeq or Acxiom) to Microsoft, so these data sources are named after their vendor’s name. For example, if you want to use the point of interest data in the North American region provided by NavTeq, use the NavTeq.NA data source.

Along with the vendor-supplied point of interest data sources, MapPoint Web Service also provides one sample point of interest database for a fictitious company called Fourth Coffee Company. The data source for this company, MapPoint.FourthCoffeeSample, contains fictitious coffee shops across North America and Europe. This data source can be used as an example of how your business data can be uploaded as point of interest data to the MapPoint Web Service servers.

Tip

For a full list of point of interest data sources and the entity types supported by them, check Microsoft’s online documentation at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/mappointsdk/html/index.asp.

Icon data sources MapPoint Web Service provides one icon data source, MapPoint.Icons, which contains over 900 icon images that you can use with the Pushpin object when rendering a map. Each icon image in the icon data source is indexed with either text or numbers that can be used in your application to indicate to use of a pushpin. Identify the icon data source for the pushpin image, and then render that pushpin using one of the map data sources.

Tip

You can see a full list of icons in Microsoft’s online documentation at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/mappointsdk/html/mpn35devTablesIcons.asp

Now that you know what MapPoint data sources are, let’s look at customer data sources in detail.

Customer data sources

Customer data sources are created and maintained by customers that use MapPoint Web Service; however, the actual data is hosted on MapPoint Web Service servers. For example, if your company wants to show your office locations on MapPoint Web Service-rendered maps, you need to upload your office location data to MapPoint Web Service servers. The uploaded data is geo-coded and stored in a data source specifically associated with your MapPoint Web Service account. This data source is only accessible by you, and no other MapPoint Web Service customer can read or write to this data source.

You will be automatically assigned a custom data source with a pre-assigned name when you sign up for the MapPoint Web Service, but you can also create your own data sources apart from the pre-assigned one. For example, if your company name that is registered with MapPoint Web Service account is CompanyXyz, and your MapPoint Web Service ID is 6909, your default data source name will be CompanyXyz.6909, and any new data sources that you create will contain this name as their first part. If you want to create a new data source to store only your office locations with the name Office, the data source name will be CompanyXyz.6909.Office.

You can create new data sources either manually by using the Customer Services web site (https://mappoint-css.partners.extranet.microsoft.com/cscv3/) or programmatically by using the Customer Data Service API (see Chapter 8 for more details).

MapPoint Web Service currently supports only point of interest data and icon data for customer data sources , which means that you can only upload points of interests and your own icons to use in your MapPoint Web Service applications.

With so many data sources available in MapPoint Web Service, if you are wondering how to remember which data source performs each location-oriented task, you can find out the capabilities of any data source programmatically in MapPoint Web Service.

MapPoint Web Service data source capabilities

Each data source in the MapPoint Web Service environment supports certain location-oriented and non-oriented tasks. The data source capabilities define which data source supports each task.

The data source capabilities are the metadata defined for each data source, which you can use to find out which tasks that data source can support. For example, to find out what all the tasks that can be performed by the data source MapPoint.NA are, query the capabilities metadata using the CommonServiceSoap API. The data source capabilities are programmatically represented as the DataSourceCapability flagged-enumeration whose values are shown in Table 5-3.

Table 5-3. Data source capabilities enumeration

Name

Flag

Function

CanDrawMaps

1

Used to render maps

CanFindAddress

16

Used to find addresses

CanFindNearby

4

Used for proximity searching and attribute searching

CanFindPlaces

2

Used for finding places

CanRoute

8

Used for calculating driving directions and creating routes

HasIcons

32

Used for setting pushpin icons

Data source capabilities can be grouped by their basic functionality, such as find, render, and route, which we will look at in detail in the next couple of chapters; also remember that one single data source can support more than one of these capabilities. For example, the MapPoint.NA data source supports CanDrawMaps, CanFindAddress, CanFindPlace, and CanRoute.

Finally, before we wrap up our discussion on data sources, you need to be familiar with which languages these data sources support .

Language support in data sources

Although MapPoint Web Service currently supports 10 languages, not every data source currently supports all 10 languages. The core geographic coverage data sources, MapPoint.NA, MapPoint.EU, MapPoint.BR, and MapPoint.AP, support the nine languages shown in Table 5-4.

Table 5-4. Languages supported in data sources

Language (Country/Region)

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 sources MapPoint.Moon and MapPoint.World support all of these languages as well as Japanese (language code ja and LCID 1041).

It is also important to note that the MapPoint.Icons data source and all MapPoint point of interest data sources are available only in United States English.

Language preference in MapPoint Web Service is exposed via the CultureInfo object using the UserInfoHeader class, which you can use to set a desired culture Name or Lcid value from the previous table. The following code shows how to request a culture specific setting during a FindService call:

    //Create a Find Service proxy class instance
    FindServiceSoap find = new FindServiceSoap();
    //Assign Credentials

    . . .
    //Set culture specific settings
    //Create the user info header instance
    find.UserInfoFindHeaderValue = new UserInfoFindHeader();
    //Initialize culture value and set italian
    find.UserInfoFindHeaderValue.Culture = new CultureInfo();
    find.UserInfoFindHeaderValue.Culture.Name = "it";
    //Assign data source name and invoke find method
    . . .

When you set a specific culture for the Find Service, the find results returned by the service are expressed in the culture requested. For example, if you try finding Redmond, WA with “en-US” as your culture information, you get Redmond, Washington, United States as the display name of the found entity, but the same find request returns the “Redmond, Washington, Stati Uniti d’America” when you set the culture info as “it” to get return results in Italian culture format.

Where Are We?

So far, we have looked at several aspects of MapPoint Web Service programming, such as getting started with MapPoint Web Service, understanding the core service components, security and configuration implications, MapPoint data sources and customer data sources, and data source capabilities and languages.

With this introduction as a background, the next chapter will take an in-depth look at MapPoint Web Service Find APIs.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.41.205