Section 1.3. Developing Location-Enabled Applications


1.3. Developing Location-Enabled Applications

Location-enabled applications know how to interpret and process location information. The kinds of applications that fall into this category include:


Generic maps and directions

Provide basic planning-related functionalities, such as displaying a desired location on a map and calculating driving directions from one point to another point. For example, both MapPoint 2004 and Streets & Trips 2004 provide this functionality right out of the box.


Location-based data visualization (or thematic mapping )

Helps you to visualize the data using geographic extent. For example, using MapPoint 2004, you can view information such as population statistics in any given city in the United States, or color-code the map based on population density.


Store Finders, ATM Finders, and similar applications

Find points of interest around a desired location. For example, you can find a nearby coffee shop when you are traveling in a new town or find local bloggers in the area in which you live.

To build this category of applications using MapPoint technologies, you have two choices: disconnected applications using MapPoint 2004, and connected applications using MapPoint Web Service.

1.3.1. Disconnected Applications Using MapPoint 2004

MapPoint 2004 is a powerful desktop mapping application that provides a rich set of APIs for both managed and unmanaged application development. MapPoint 2004 is well-suited for disconnected location-enabled application architecture, which means that the location-enabled application and required location data reside locally on the host computer's hard disk, and no network connectivity is required for the application's functionality.

Along with normal location-based APIs, such as Find, Route, and Render, MapPoint 2004 also offers a rich set of functions (also APIs) for thematic mapping, territory management, and spatial data import from a variety of source formats such as Excel, Access, Txt, and so on.

The APIs provided by MapPoint 2004 are COM- (Component Object Model) based APIs; however, thanks to .NET Framework runtime callable wrappers , you can program with the COM APIs using .NET's managed code. MapPoint 2004 also provides an ActiveX control that enables MapPoint 2004 application integration into your applications so that you can reuse most of the MapPoint 2004's application user interface.

Figure 1-3 shows how your applications stack on MapPoint 2004 architectural layers.

When you redistribute applications that you have developed using MapPoint 2004, make sure that the target machines have MapPoint 2004 installed as well. It is also possible to include MapPoint 2004 runtime and data along with your application if you become a MapPoint 2004 application reseller. Also, note that the MapPoint 2004 licensing model prevents you from developing web-based applications using the ActiveX control.

Figure 1-3. MapPoint 2004-based application stack


For further details on application redistribution using MapPoint 2004 information, go to http://msdn.microsoft.com/library/?url=/library/en-us/mappoint2004/BIZAPIAboutDistributingMapPointControl.asp?frame=true.


With this introduction, let's look at a simple Windows application that uses MapPoint 2004 ActiveX control to display a map.

1.3.1.1. Hello, MapPoint 2004!

Using Visual Studio .NET , you can program with MapPoint ActiveX Control just like any other .NET Windows Forms Control.

If you do not have MapPoint ActiveX Control added to your Visual Studio .NET Toolbox, see Chapter 2 to learn about how to prepare your development environment to use MapPoint ActiveX control.


When you drag-and-drop the MapPoint ActiveX Control onto a Windows Form, Visual Studio .NET automatically adds a reference to your project and defines a private instance of the ActiveX control:

     private AxMapPoint.AxMappointControl axMappointControl1;

Using this ActiveX control instance, you can open up a map and place a pushpin at its center:

     //Create a new map     axMappointControl1.NewMap(MapPoint.GeoMapRegion.geoMapNorthAmerica);     //Get map center location     MapPoint.Location location =  axMappointControl1.ActiveMap.Location;     //Add a pushpin at this location     MapPoint.Pushpin pushpin           = axMappointControl1.ActiveMap.AddPushpin(location, "Center");     //Assign a symbol     pushpin.Symbol = 64;     //Select and highlight the location     pushpin.Select( );     pushpin.Highlight = true;     //Write annotation     pushpin.Note = "This is the centroid of America!";     //Show tooltip (Balloon State)     pushpin.BalloonState = MapPoint.GeoBalloonState.geoDisplayBalloon;

When you place the above code in the Form.Load event handler and run the application, the Windows Form displays the map as shown in Figure 1-4.

Figure 1-4. Displaying a map with a pushpin using MapPoint ActiveX Control


Finally, MapPoint 2004 provides required location data locally; however, the data available with MapPoint 2004 contains only map data for the United States, Canada, and Mexico. To access map and location data for Europe, use MapPoint 2004 Europe Edition. At the time of this writing, MapPoint 2004 supports only North America, Western Europe, and some parts of Eastern Europe.

1.3.2. Connected Applications Using MapPoint Web Service

MapPoint Web Service is a Microsoft-hosted XML Web Service that is fully compliant with SOAP and WSDL standards. MapPoint Web Service makes it very easy for you to develop connected location-enabled applications. One of the advantages of using MapPoint Web Service is that the location data and the necessary processing framework are hosted by Microsoft on MapPoint servers, so your applications remain very thin and always have up-to-date location data. In addition, since MapPoint Web Service is a SOAP XML Web Service, it is possible to develop location-based applications that are both platform agnostic and programming language agnostic.

Along with normal location-based APIs, such as Find, Route, and Render, MapPoint Web Service also offers a full set of APIs for custom points of interest data upload and download to enable automated data management.

The APIs provided by MapPoint Web Service are SOAP-based APIs that can be accessed using any XML-enabled programming languages. Using the .NET framework makes it easy to develop applications with MapPoint Web Service; for example, using the following code, you can render a map with a pushpin similar to Figure 1-4:

     //Create an instance of the render service object     RenderServiceSoap renderService = new RenderServiceSoap( );     renderService.Credentials =              new System.Net.NetworkCredential("myid", "mypassword");     //Create an instance of MapSpecification     MapSpecification mapSpec = new MapSpecification( );     //Assign data source name     mapSpec.DataSourceName = "MapPoint.NA";     //Add pushpin     //Create and add a pushpin     Pushpin pin = new Pushpin( );     //Assign data source     pin.IconDataSource = "MapPoint.Icons";     //Assign icon name     pin.IconName = "1";     //Assign label     pin.Label = "This is the centroid of America!";     //Assign location     pin.LatLong = new LatLong( );     pin.LatLong.Latitude = 38.79;     pin.LatLong.Longitude = -98.79;     //Add pushpin to map specificiation     mapSpec.Pushpins = new Pushpin[] {pin};     //Create options     mapSpec.Options = new MapOptions( );     //Assign options     mapSpec.Options.Format = new ImageFormat( );     mapSpec.Options.Format.Height = this.mapImage.Height;     mapSpec.Options.Format.Width = this.mapImage.Width;     //Assign view by height and width if it is the view     ViewByHeightWidth vbh = new ViewByHeightWidth( );     vbh.Height = 400;     vbh.Width = 600;     vbh.CenterPoint = pin.LatLong;     //Zoom out to see the entire country     mapSpec.Options.Zoom = 10;     //Assign view     mapSpec.Views = new MapView[] {vbh};     //Get map     MapImage[] mapImages = renderService.GetMap(mapSpec);     this.mapImage.Image = new Bitmap(new System.IO.MemoryStream(mapImages[0].MimeData.Bits)); 

If you don't understand anything about these steps, don't worrywe will look at Map Rendering in detail in Chapter 8. When the code is run, the map is displayed as shown in Figure 1-5.

It looks like a lot more code than MapPoint ActiveX Control, but it is very simple once you understand the MapPoint Web Service object model. Also, it is important to note that the above code returns the binary form of the map image, which displays the map in a .NET Windows Forms Picture Box control; when you use a Web Form application using ASP.NET, you can request the map in a URL format, which can be used in an HTML IMG tag.

Figure 1-6 shows how your applications build on top of MapPoint Web Service architectural layers.

Location data in MapPoint Web Service is hosted on Microsoft MapPoint servers, and all of the map and location data is available for developers via the programmable APIs. This provides greater flexibility in building global location-based applications that work for multiple countries and regions.

Location data in the MapPoint Web Service environment is represented in terms of data sources; each dataset represents data for a particular country or region; for example, North American region map and location data is contained in the MapPoint.NA data source. So, if you develop a store finder application using MapPoint Web Service using the MapPoint.NA data source, and you want to reuse the application code for Europe, change the data source name from MapPoint.NA to MapPoint.EU (compare the procedure used here to one using MapPoint 2004). Location-based applications can be configured to use just about any map data, since MapPoint Web Service provides the loose coupling between your application layer and the data layer.

Figure 1-5. Displaying a map using MapPoint Web Service


Figure 1-6. MapPoint Web Service-based application stack


MapPoint Web Service currently supports map and location data for countries and regions in North America, Europe, and Pacific Asia.




Programming MapPoint in  .NET
Programming MapPoint in .NET
ISBN: 0596009062
EAN: 2147483647
Year: 2005
Pages: 136
Authors: Chandu Thota

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net