Click here to Skip to main content
Click here to Skip to main content

MapPoint, SmartPhone and C# - Part 1

By , 8 Nov 2004
 

Introduction

When it comes to mobility, location based services and applications take precedence today as the business world is rushing towards mobility to gain the associated business gains. On the technology front, Microsoft has already made its presence very strongly on all these technology areas.

For Location Based Applications, the new MapPoint SDK 3.5 provides an XML Web Service to allow us to build location based services. This SDK helps us to get very high quality maps, identify a specific location like pizza shops, hospitals etc., and also provides a route map to reach the desired destination. You can download the SDK here.

On Mobility front, Microsoft already has a obtained a strong space with its Microsoft SmartPhones and PPCs. Read more on mobility here.

In this two part article, we would leverage on MapPoint SDK using C# and build some simple applications. In this first part of the article, we shall render a map for the given address on a Microsoft SmartPhone.

Let's start with MapPoint.

MapPoint exposes four web-services:

  1. Find Service – Helps us to locate address, retrieve geocode (Latitudes, Longitudes), geographic entities.
  2. Render Service – This service allows us to render maps for the given address, and set the size of the rendered map and the desired view of the map. Also, we can place pushpins which would serve as the visual cue for the viewers.
  3. Route Service – This service allows us to generate routes, calculate distances between routes, and provide driving directions.
  4. Common Service – Serves as a utility service, which is common for the three webservices listed above. Provides services like CountryRegion Information and Map datasource information.

In order to use MapPoint webservices, you need to obtain a developer account. Check Microsoft to signup. You can signup and receive an evaluation account, or if you are a MSDN subscriber, you can receive a 1 year free subscription.

Fine, let’s get into the code now.

I shall dissect the code of our application. But I would strongly encourage to read the basics at MapPoint SDK. Explaining the same here would just be a duplication, and would not add any value.

Download and open the project solution. Now, open the MapPointWrapper.cs and replace your MapPoint developer username, password for the _mapPointUserName, and _mapPointPassword const strings.

The Form1.cs contains a Menu object, and would get the address details for the map to be rendered.

On click of the “Get Map” menu, an address object is created, and DataSource is set to “MapPoint.NA”. Following are the data sources available.

  1. MapPoint.EU – Europe
  2. MapPoint.NA – North America
  3. MapPoint.BR – Brazil
  4. MapPoint.World – World
  5. MapPoint.Moon - Lunar Map

The following code would retrieve the location details based on the given address, using the FindServiceSoap Webservice. The webservice must be authenticated with the MapPoint developer account. We need to supply the data source name and the address.

public static void GetAddress(Address address, string DataSourceName, 
         out indResults Location, out ViewByHeightWidth[] Views) 
{
  try
  {
    FindServiceSoap locationService = new FindServiceSoap();
    locationService.Credentials = new 
               System.Net.NetworkCredential(_mapPointUserName, 
               _mapPointPassword); 

    locationService.PreAuthenticate = true; 

    FindAddressSpecification locationData = new FindAddressSpecification();
    locationData.DataSourceName = DataSourceName;
    locationData.InputAddress = address;

    Location = locationService.FindAddress(locationData);

    Views = new ViewByHeightWidth[1];
    Views[0] = Location.Results[0].FoundLocation.BestMapView.ByHeightWidth;
  }
  catch(Exception ex)
  {
    throw new Exception(ex.Message,ex);
  }
}

After obtaining the location details, this data is further sent to GetMap method. This method uses the “RenderServiceSoap” Web Service. This service again needs authentication details. MapPoint provides Pushpins, a visual cue to pinpoint the address on the map. You can choose from the default set of icons and give an appropriate name. Additionally, a MapSpecification object is created which would hold the view, pushpins, image format etc. RenderService’s GetMap is invoked to retrieve the appropriate image, this is retrieved as a stream and shown as a bitmap.

public static Bitmap GetMap(FindResults Location, 
         ViewByHeightWidth[] Views,string DataSourceName,
         Point MapDimensions)
{
  try
  {
    RenderServiceSoap renderService = new RenderServiceSoap();
    Pushpin[] pushpins = new Pushpin[1];
    MapSpecification mapSpec = new MapSpecification();
    renderService.Credentials = new 
          System.Net.NetworkCredential(_mapPointUserName, 
          _mapPointPassword);
    renderService.PreAuthenticate = true;

    pushpins[0] = new Pushpin();
    pushpins[0].IconDataSource = "MapPoint.Icons";
    pushpins[0].IconName = "0";
    pushpins[0].Label = Location.Results[0].FoundLocation.Entity.Name;
    pushpins[0].LatLong = Views[0].CenterPoint;
    pushpins[0].ReturnsHotArea = true;

    mapSpec.DataSourceName = DataSourceName;
    mapSpec.Views = Views;
    mapSpec.Pushpins = pushpins;
    mapSpec.Options = new MapOptions();
    mapSpec.Options.Format = new ImageFormat();
    mapSpec.Options.Format.Width = MapDimensions.X;
    mapSpec.Options.Format.Height = MapDimensions.Y;
    MapImage[] mapImages = renderService.GetMap(mapSpec);

    System.IO.Stream streamImage = new 
           System.IO.MemoryStream(mapImages[0].MimeData.Bits);
    Bitmap bitmap = new Bitmap(streamImage);
    return bitmap;
  }
    catch(Exception ex)
  {
    throw new Exception(ex.Message,ex);
  }
}

That's all... we are done ... here is the rendered map. Also, note the pushpin in the map to identify the exact location.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Logu Krishnan
Web Developer
India India
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionHow can i get vertices of map in mapppoint webservicesmemberkhaleek15 Mar '07 - 20:59 

I am working on mappoint web services.
Pls tell me how i can access Vertices of a map in msppoint webservices.
What i want actually i input the location and it return me vertices of that map location.
I will very thankfull to you.
 



Generalin ASPmembermeenakshi vasudevan22 Nov '05 - 22:10 
how can i use mappoint in ASP.net without deploying in any other device??
GeneralRe: in ASPmemberkarthikeyan ganesan7 Jun '06 - 1:37 
You can Deploy MapPoint Web Service ni the server. Render the Map as Image and send it to the client.
 

GeneralHelp me out . It is not workingsussAnonymous21 Oct '05 - 8:54 
I am trying to use this code with a GPS receiver I have but porblem is that I'm not able to open project files and when i try to open .csdproj file it's only giving me a file name on visual studio 2003. How do I use GPS receiver to use mappoint web services? please give me a reply asap. Thank you.
GeneralHelp Me OutmemberJay Dubal21 Nov '04 - 21:40 
Dear Sir,
 
I am not receiving the Eval Code from M$, can you please suggest me a solution. I am not able to run the webservice without that. I have less time.
 
Thanks in advance.
JayMad | :mad: Confused | :confused:
 

GeneralWill it work for all countries like Indiamemberrajpatil21 Nov '04 - 1:23 
Hello, can i generate a map for location in India by providing address and can I use emulator of smartphone means what is required to view the output?
Thanks
GeneralRe: Will it work for all countries like IndiamemberLogu Krishnan21 Nov '04 - 19:17 
No... detailed Maps has been defined only for North America, Europe, Brazil... but you can use the world map and use lat,long to locate the place in india, but not by address... BTW you can emulate it or deploy it on a real phone...
GeneralRe: Will it work for all countries like Indiamemberkarthikeyan ganesan7 Jun '06 - 1:41 
Presently MapPoint hold the Data (Data Source) for (Europe,North America & Canada, Brazil, World and Lunar Map).
 
You can use the Wold DataSource to Display the major cities in India. But you can't drill down to address.
 
Even though you give the full Address it will try to match the city and disply the map.
 


General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web04 | 2.6.130523.1 | Last Updated 9 Nov 2004
Article Copyright 2004 by Logu Krishnan
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid