spacer1
spacer2 1_1 1_2
2_1
 Subscribe
 The MP2K Update!
 
 
 
 Magazine
Front Cover
What's New
Articles
News
Sample Data
Gallery
Advertise
About
 Features
MapPoint 2013
Press Releases
MapPoint Forums
Companies
Link to MP2Kmag
Wish List
MapPoint Trial
Authors
 Earlier Content
Past News Items
Past What's New Announcements
 Sponsors
 Order

MapPoint 2013

Programming MapPoint in .NET

MapPoint Book

  Spatial Community
SVG Tutorials
MapPoint

Map Visitors

  ARTICLES  


Implementing Location-Based Functionalities with the MapPoint Web Service

This article by Mohanraj Annamalai illustrates how to find the center point from a set of Latitudes and Longitudes. The article also discusses how to programmatically generate a map using the Microsoft MapPoint Web Service and implement interactive features like: re-centering a map based on the clicked location, panning north, south, east, and west.

When implementing location-based functionalities (e.g. rendering maps) for business applications, finding the center of the data set is an important step. The mode “the number with the highest frequency” - does a nice job in telling where the center of the data set is. This article illustrates how to find the center point from a set of Latitudes and Longitudes. The article also discusses how to programmatically generate maps using the Microsoft MapPoint Web Service and implement interactive features like: re-centering a map based on the clicked location, panning north, south, east, and west.

The ASP.NET (VB.NET) source code for this article illustrates scenario of generating an area map in Los Angeles, CA with a set of (fictitious) drug store locations. The following are the requirements to run the source code:

 • .NET 2.0 frame work, and VS.NET 2005
 • SQL Server 2005 Express edition
 • MapPoint Web Service developer account to access the staging environment. Note: you can apply for developer account at this URL - https://mappoint-css.partners.extranet.microsoft.com/MwsSignup/Eval2.aspx.

Download the code sample.

The SQL server database (in the App_data folder) has one table with following columns Name, Address, City, State, Zip, Latitude, and Longitude. In a real life scenario we know only the Address of the locations, but for the simplicity, I am assuming Latitude and Longitude are available in the database. The Microsoft MapPoint web service provides API functions to calculate Latitude and Longitude of any location based on its address. So in any real-life application when the location details are stored, an extra step of finding and storing Latitude and Longitude will help in the future.

Generating dynamic maps programmatically for business applications involves the following aspects:

 • Based on the user’s query (input parameters) find a set of relevant locations from the database.
 • Render a map using the resulting locations details.
 • Adding interactive features to the map.

To create dynamic maps, the MapPoint Web Service provides Find, Route, and Render services along with some utility services. We can generate maps using these services in many approaches like maps based on proximity search or by bounding rectangle etc. In the given source code maps are generated with render services of MapPoint using a center point. There are two ASP.NET pages in the given sample code. One page (default.aspx) has all the user interface controls like text box, command button, and image buttons. The other page (MapImg.aspx) has the logic of generating the dynamic map using Render services of MapPoint. The Page_Load event of MapImg.aspx deals with three different cases. We will take a look at the case of generating map based on the given City and State. Query the database to get an ordered (by Latitude and Longitude) list of locations for the given City and State. Loop through the fetched DataTable to create array of locations and its pushpins to generate the map. The next step is to find the center point of the found locations. To do that, loop through all the locations again rounding them to two decimal places and find the mode of the data set. The found mode gives one set of Latitude and Longitude which is used as the center point of the map. Based on the given Scale and dimensions (height and width) and the Center point the map will include pushpins. Depending on the specific data you can increase or decrease the scale, dimensions and rounding precisions to generate maps with desired number of pushpins.

To add interactive features to the map, you have to render the map with the same locations but recalculating the Center Point. In the case of making the user-clicked position as the center point. Use the Image button web server controls event arguments (pixel co-ordinates). By passing the pixel co-ordinates to the ConvertToLatLong API of the Render services, the new center point is calculated and it is used to generate the map.

To pan north or south, increase or decrease previous center-point’s Latitude and keep Longitude same. Similarly to pan east or west, increase or decrease previous center-point’s Longitude and keep Latitude same.

Before running the provided source code, in the web.config file change the key values MPUser and MPPass to the valid developer account user-id and password. Run the source code for this article, in the screen enter Los Angeles and CA for City and State text boxes then click the Go button to generate a map as shown in the figure 1.


Figure 1 - click on the thumbnail to view the full screenshot

In the map when you click on the push pin Asia Drugs, a map with that location as center is generated as shown in figure 2.


Figure 2 - click on the thumbnail to view the full screenshot

Now when you click the East button (right arrow), the following map is generated:


Figure 3 - click on the thumbnail to view the full screenshot

References

 • MapPoint web service product information: http://www.microsoft.com/mappoint/products/webservice/default.mspx
 • MapPoint web service requirements: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/mappointsdk/html/Require.asp
 • MapPoint web service documentation: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/mappointsdk/html/MPNET.asp

Discuss this story in the forum.

Author: Mohanraj Annamalai
Email: mohanraj_a(AT)hotmail.com
URL: http://www.unisys.com
Mohanraj Annamalai is a solutions architect and lead developer of Microsoft technologies-based web applications at Unisys Corporation. He has ten years of software design and development experience in various areas like Web-Based applications, Windows Forms applications, database management systems and document imaging/workflow.



Google
 
MP2Kmag Internet


 Recent Discussion
-GCPowerStation v17.2
-GCPowerStation v17.2
-Gaussian 09W v8.0 Rev B.01 SMP
-Gaussian 09 E.01 Linux64
-Atmel Studio v.7.0.1931
-Steinberg Cubase Elements v9.5.40 WiN
-Nero Platinum 2019 Suite 20.0.05900 Multilingual
-Serif DrawPlus X8 14.0.0.19
-PROMT Master 19 Final + PROMT 19 Dictionary Collection
-Apple Logic Pro X v.10.4.2 Multilanguage (MacOSX)
-PROMT Expert 19 Final + PROMT 19 Dictionary Collection
-Waves Complete v2018.10.16 WiN by R2R
-VMware Fusion Pro 10.1.1 MacOSX
-Foxit Phantompdf Business v.9.3.0.10826 Multilanguage
-Bluestacks v4.31.56.2510 Multilingual
-Xara Web Designer Premium 16.0.0.55162 (x64) Portable
-Adobe Bridge CC 6.1.1.10 Update 3 by m0nkrus
-Garmin MapSource v5.4
-Alien Skin Exposure X4 Bundle 4.0.2.43 | macOS
-Unity Asset Cubebrush - Scrap City Assets 1.0 x64
-Magix Samplitude Pro X3 Suite v.14.4.0.518 Multilanguage
-Waves Complete v2018.10.16
-Oxygen XML Editor 18.0 (Win/Mac/Lnx)
-Steinberg Cubase Elements v9.5.40 WiN
-The Foundry Nuke Studio 11.2v4 Win x64
 Resources
Browse GIS books and periodicals
Find a MapPoint Partner or Consultant
Real Estate Columbia Homes for Sale by Owner


Want Your Site To Appear Here?

   © 1999-2012 MP2K. Questions and comments to: website@mp2kmag.com
  Microsoft and MapPoint 2002/2004/2006/2009/2010/2011/2013 are either trademarks or registered trademarks of Microsoft.