Thanks.
I have solved the problem. It was some kind of missconfiguration of VC++.
If any of you are interested in what i'm doing here is my code (working).
It makes reverse geocoding by an spiral algorithm and also saves the map.
MapPointApp.cpp Code:
/******************************************
* *
* CGI de conversion de coordenadas GPS *
* *
******************************************/
#include "ComInterfaces.h"
#include <stdio.h>
using namespace MapPoint;
MapPoint::_ApplicationPtr g_pMapPoint = NULL;
void main( int argc, const char*argv[] )
{
char *endptr;
//first and second arguments are latitude and longitude
double lat = strtod(argv[1], &endptr);
double lon = strtod(argv[2], &endptr);
CoInitialize( NULL );
/********************
* Initialization *
********************/
g_pMapPoint.CreateInstance( "MapPoint.Application" );
g_pMapPoint->Visible = false;
g_pMapPoint->PutWindowState( geoWindowStateMinimize );
g_pMapPoint->PutCaption( "MapPoint 2004 is in Automation Mode!" );
g_pMapPoint->PutUnits( geoKm );
_MapPtr myMapPtr = g_pMapPoint->ActiveMap;
/**********************************
* Find street name by lat/long *
**********************************/
int step = -1;
int step_m = -1;
int mult = 0;
StreetAddressPtr sap;
LocationPtr latlongPos;
LocationPtr latlongPosInicial = myMapPtr->GetLocation(lat,lon,1);
printf("Position(lat/long): %s\n", (char*)latlongPosInicial->Name);
VARIANT idx;
VariantInit( &idx );
V_VT(&idx) = VT_I4;
V_I4(&idx) = 1;
for(int j=0;j<1000;j++){
latlongPos = myMapPtr->GetLocation(lat,lon,1);
latlongPos->GoTo();
FindResultsPtr resultsPtr =
myMapPtr->ObjectsFromPoint( myMapPtr->LocationToX(latlongPos),
myMapPtr->LocationToY(latlongPos));
if(resultsPtr->GetCount()>0){
LocationPtr res = resultsPtr->GetItem( &idx );
sap = res->StreetAddress;
if(sap!=NULL){
printf("Street: %s\n", (char*)sap->GetValue());
//latlongPosInicial = res;
printf("Error margin: %.3f Km\n",
llatlongPosInicial->DistanceTo(latlongPos));
goto found;
}
}
//Increases espiral by 0.00002 degrees
step = (step+1)%4;
step_m = (step_m+1)%3;
if(step_m == 0) mult+=1;
switch(step){
case 0:
lat+=0.00002*mult;
break;
case 1:
lon+=0.00002*mult;
break;
case 2:
lat-=0.00002*mult;
break;
case 3:
lon-=0.00002*mult;
break;
}
}
printf("Street not found\n");
found:
/******************
* Map creation *
******************/
PushpinPtr pinAddressPtr = myMapPtr->AddPushpin( latlongPosInicial,
"You are here"/*nombre_calle*/ );
if(sap!=NULL) pinAddressPtr->PutNote(sap->GetValue());
pinAddressPtr->PutSymbol( 82 );
pinAddressPtr->BalloonState = geoDisplayBalloon;
pinAddressPtr->Highlight = true;
myMapPtr->SaveAs( "C:\\MapIsHere", geoFormatHTMLMapAndDirections, false );
pinAddressPtr->Highlight = false;
pinAddressPtr->BalloonState = geoDisplayBalloon;
pinAddressPtr->Delete();
myMapPtr->Saved = true;
g_pMapPoint->Quit();
CoUninitialize();
//end
}
It is a console application. You pass the latitude and longitude values and then it prints the nearest street, the real distance to the point specified (error margin) and saves the map as an html document.
Thanks a lot for all your help and for the article about c++ automation.
Now this works perfect
