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 2009
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 2009

Programming MapPoint in .NET

MapPoint Book

  Spatial Community
ViaVirtualEarth
SVG Tutorials
MapPoint

Map Visitors

 Direct Media

Travel Insurance Compare over 450 travel insurance policies (inc. annual multi-trip, single trip & winter sports)

  ARTICLES  


MapPoint Automation with C/C++ - Part 1

This is the first of three articles by Sergey Kostrov on automating MapPoint with C/C++ starting with a simple C/C++ application.

A Simple C/C++ Application

As a C++ software developer I’m very surprised by the lack of documentation from Microsoft about MapPoint Automation with C/C++. It looks like Microsoft wants to “move” everybody to the “.NET Universe” and completely ignores some reality of the world when some C++ programmers don’t want to give up…

On MP2Kmag there are already a couple of articles related with automation of MapPoint from an application written in C++. In Part 1 of my article I would like to demonstrate what should be done to initialize MapPoint and then how to use MapPoint’s COM API.

I assume that you use Microsoft Visual C++ and to simplify development I also recommend using Type Library mpna82.tlb because it gives lots of advantages and increases productivity. With that approach you don’t have to do low-level COM programming. If you’ve installed the MapPoint application to a default folder you can find mpna82.tlb file at the C:\Program Files\Microsoft MapPoint folder.

The main goal of this article is to help you at the beginning and as soon as basic things are clear all the rest is easier. This article is not intended to teach you how to do C/C++ programming or what OLE Automation is, and should be considered as a set of recommendations.

Here are source codes for a simple C/C++ application that initializes MapPoint, finds an address, puts pushpin and saves a map on the hard drive.

///// ComInterfaces.h /////

#ifndef _COM_INTERFACES_H
#define _COM_INTERFACES_H

#pragma once
#pragma pack( push, ComInterfaces )
#undef EOF
#import "C:\Program Files\Microsoft MapPoint\mpna82.tlb" no_implementation
#pragma pack( pop, ComInterfaces )

#endif

///// ComInterfaces.cpp /////

#include "ComInterfaces.h"

#pragma once
#pragma pack( push, ComInterfaces )

#import "C:\Program Files\Microsoft MapPoint\mpna82.tlb" implementation_only

#pragma pack( pop, ComInterfaces )

///// MapPointApp.cpp /////

#include "ComInterfaces.h"
…
MapPoint::_ApplicationPtr g_pMapPoint = NULL;
…
void main( void )
{
CoInitialize( NULL );

g_pMapPoint.CreateInstance( "MapPoint.Application" );
g_pMapPoint->Visible = true;
g_pMapPoint->PutWindowState( geoWindowStateNormal );
g_pMapPoint->PutCaption( "MapPoint 2004 is in Automation Mode!" );
g_pMapPoint->PutUnits( geoKm );

_MapPtr myMapPtr = g_pMapPoint->ActiveMap;

FindResultsPtr resultsPtr = myMapPtr->FindAddressResults
(
	“400 Coronado Dr”, “Denton”, "", “TX”, “76209”, geoCountryDefault
);

VARIANT idx;
VariantInit( &idx );
V_VT(&idx) = VT_I4;
V_I4(&idx) = 1;
LocationPtr locAddressPtr = resultsPtr->GetItem( &idx );
PushpinPtr pinAddressPtr = myMapPtr->AddPushpin( locAddressPtr, "Your property is here" );

pinAddressPtr->PutSymbol( 57 );					// Red triangle ( big )

pinAddressPtr->BalloonState = geoDisplayBalloon;
pinAddressPtr->Highlight = true;
locAddressPtr->GoTo();

myMapPtr->ZoomIn();

myMapPtr->SaveAs( "C:\\$MapIsHere", geoFormatHTMLMapAndDirections, false );

pinAddressPtr->Highlight = false;
pinAddressPtr->BalloonState = geoDisplayNone;
pinAddressPtr->Delete();

myMapPtr->Saved = true;

g_pMapPoint->Quit();
…
CoUninitialize();
}

A few comments and recommendations

  • As you can see source codes are very straightforward and even if you don’t have any experience with C/C++ programming it takes little efforts to study the example;
  • Take a look at two compiler-generated files mpna82.tlh and mpna82.tli. These two files are an invaluable source of the information because all interfaces, smart pointer typedef declarations and enumerations described there. It is very useful to run this example under the control of the Visual C++ Debugger in order to see how it actually works;
  • In the example we save a map on the drive C: in the folder $MapIsHere and MapIsHere.htm file can be used to view the map in an Internet browser. Enclosed are also two pictures that give you an idea how the results look like in automated MapPoint and Internet Explorer:


(click on the image to view the full screenshot)


(click on the image to view the full screenshot)

Discuss this story in the forum.

Author: Sergey Kostrov
Email: sergeykostrov(AT)hotmail.com
URL: http://www.zaio.com/
Sergey Kostrov is a C++ / Database software developer with Zaio Corp. located in Calgary, Alberta, Canada.



Google
 
MP2Kmag Internet


 Recent Discussion
-bingmaps: RT @ChrisPendleton: After much ado, the Bing Twitter Maps EMBED feature is LIVE (for real, this time!): http://bit.ly/cUslPQ. @BingMaps
-bingmaps: @USAToday talks to @ChrisPendleton about #BingMaps http://bit.ly/cdzZqJ
-MapPoint 2010 optimize gives different results
-Mappoint on an access form
-blank screen when searching place or address
-Embed Bing Maps Twitter Maps On Your Site
-bingmaps: RT @JohannesKebeck: New blog post: http://tinyurl.com/ygmlayc - Spatial Data Management and Data Visualization with SQL Server 2008 & Bi ...
-Getting 2006 symbols in 2010?
-bingmaps: At #wherecampeu today? Look out for @johanneskebeck and @mrtea72 from the #BingMaps team
-Using MapPoint to see Deaths
-Spatial Data Management and Data Visualization with SQL Server 2008 & Bing Maps
-bingmaps: Join the UK #BingMaps team for the finance and insurance sector webcast tomorrow http://bit.ly/chMYcb
-Bing Maps at MIX10!
-Bing Maps at MIX10!
-bingmaps: Want live Twitter and Maps on your website, use the new widget from Bing Maps: http://bit.ly/9KkFSa
-linked files
-Criteria for extracting postcodes in Mappoint Euro Ver
-Spatial Data Import COM Add-in / Shapes (SHP file)
-BingMapsDev: @jont87 For Silverlight I would start here: http://is.gd/a4BAq and then look at the Bing Maps iSDK: http://is.gd/a4C4y
-bingmaps: Channel 5's Gadget Show are impressed by #BingMaps Birds Eye (forward to 24 mins) http://bit.ly/9Cn6sY
-bingmaps: #BingMaps SXSW Panel Announced http://bit.ly/9GWSeT
-bingmaps: Bing Maps retail and supply chain webcast starts in 10 minutes. Register here: http://bit.ly/dsNNJD
-Bing Maps SXSW Panel Announced
-Check if Mappoint exists on the PC
-bingmaps: @markti Great glad you like it!
 Resources
Browse GIS books and periodicals
Best Car Contract Hire Lease Save
Find a MapPoint Partner or Consultant
Real Estate Columbia, MO Real Estate


Want Your Site To Appear Here?

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

• Replacement Cordless Phone Batteries from DSMiller
Improve your career with a computer degree LocalEDU.com
• Tim Cohn's Marketing Strategy Consultancy
• Buy Toner Cartridges at Marquee Office Solutions
• Looking for Dry Erase Boards? See Dry Erase Boards • The Search Starts Here Used Cars
• 5339 - We Know Bikes: Road Bikes / Triathlon Bikes / Mountain Bikes / BMX Bikes
• Buy Your Car Used Cars UK, Car Lease and Contract Hire