| | PieEater3142 01-05-2008, 01:56 PM Hi there,
Wondering if anyone can help me.
Im using C++ MFC with MapPoint 2002.
Im trying to calculate routes between lots of different sites and find the shortest drive time between the sites and certian buildings.
I have a fairly stable program working at the moment, however i've got to running through some test data and the program is stopping when a post code does not exist in MapPoint.
The AFX error message that comes up is:
'The requested member of the collection does not exist. Use a valid name or index number.'
I have no problem with there not being a post code match, however i need the program to keep running, and some way to tell the user which post code is not matched.
Any ideas with this would be a great help.
Cheers
PieEater3142 Eric Frost 01-05-2008, 02:07 PM Can you post your code snippet? I assume at one point you have a FindResults collection and you normally just take the first item in the collection? Can you check the number of objects or count of objects in the collection first? :?
Eric PieEater3142 01-05-2008, 02:16 PM Hi Eric,
Cheers for the quick response:
The function thats throwing the error is:
bool Route_Calculator::calculate_route(CString patient_pc, CString site_pc)
{
//reset response value
routeOK = false;
//clear route information, ready for new route info
m_Route.Clear();
//clear distance and drivetime variables
dblDistance=(double)0;
dblDriveTime=(double)0;
//MapPoint requires a variant type for passing the country
//so Variant type created with value 242 - this is the UK
VARIANT vtGeoCountry;
vtGeoCountry.vt = VT_I4;
vtGeoCountry.intVal = 242;
//find postcodes on map
CFindResults patient_loc = m_Map.FindAddressResults("", "", "", "", patient_pc, vtGeoCountry);
CFindResults site_loc = m_Map.FindAddressResults("", "", "", "", site_pc, vtGeoCountry);
//bodge factor to get around crappy microsoft product
//create variant to pass with value 1 coz it cant handle an int
VARIANT v2;
v2.vt = VT_I4;
v2.intVal = 1;
//save the locations found to type CLocation for MapPoint to process
CLocation p_lc = patient_loc.GetItem(&v2);
CLocation s_lc = site_loc.GetItem(&v2);
//add points to map
m_WayPoints.Add(p_lc, "patient");
m_WayPoints.Add(s_lc, "site");
//calculate the best route
m_Route.Calculate();
//save distance and drive time to variables
dblDistance = m_Route.GetDistance();
dblDriveTime = m_Route.GetDrivingTime();
if(dblDriveTime==0){
routeOK = false;
}else{
routeOK = true;
}
return routeOK;
}
It uses the standard MapPoint classes built when you import the ActiveX control.
It creates the error message when it gets one of the two following commands (depending which has the bad post code in):
//save the locations found to type CLocation for MapPoint to process
CLocation p_lc = patient_loc.GetItem(&v2);
CLocation s_lc = site_loc.GetItem(&v2);
Cheers for your help
PieEater Eric Frost 01-05-2008, 03:35 PM Yes, I think it makes sense. You would be trying to get item 1 from a collection with no objects.
Check the FindResults collection object in the Help File. It has five properties
Properties
Application
Count
Item*
Parent
ResultsQuality
Before you use the GetItem, I think you want to check the Count property first to see if the collection has any items.
hope that helps.
Eric PieEater3142 01-05-2008, 04:23 PM Hi Eric,
Thanks for your help.
Works like a charm.
Where is this help file of which you speak.
Im currently using the object browser in VB6 or looking at the Class view in C++ for the different functions.
Thanks again.
PieEater Eric Frost 01-05-2008, 04:42 PM Hello PieEater.
Of what pie do you like the most?
Under Start | Programs you may see MapPoint listed as a program, then go to Help and the Programming Information is at the bottom of the file.
If you don't see MapPoint in the Start menu, then you should be able to find it by going to your \Program Files\ directory and look for Microsoft MapPoint, the help file is a "MAPPOINT.chm" file you should be able to just double-click on to open. As a last resort you could search your hard drive for MapPoint.chm. If you still don't find it let me know and I can send you a copy - I don't think I have the MapPoint 2002 chm file, but the API / object model should be just about identical to the MapPoint 2004 object model.
Eric PieEater3142 01-06-2008, 05:32 PM Hi Eric,
Thanks for help file info.
All pies are good - so many to choose from - but cant go wrong with chicken and mushroom or an apple pie :mrgreen:
Another question for you if you dont mind.
I need to determine if a post code is on the isle of wight or not.
Now from the help file this would be the map.FindAddressResults function.
However the output is of type CFindResults for C++.
From the help file:
object.FindAddressResults([Street], [City], [OtherCity], [Region], [PostalCode], [Country])
So the value should come back in the OtherCity or Region field.
However how do i get the answer out in C++ - is there any way?
Cheers again
PieEater PieEater3142 01-06-2008, 06:01 PM object.FindAddressResults([Street], [City], [OtherCity], [Region], [PostalCode], [Country])Think i've got the wrong function there - was trying to get something together in vb just to see whats what (still needs to be done in c++) and it doesnt appear to give the output.
Any ideas what function can do what i need and how you can interpret the outputs?
Cheers
PieEater Eric Frost 01-06-2008, 07:32 PM Yes, you're right.
Honestly I think the easiest thing and the most reliable would be if you know the postcode range - is it consistent? for instance if all postcodes in the Isle of Wight began with
K3x xxxx through K8xx xxx or whatever
and you could just test through some string functions.
Eric PieEater3142 01-08-2008, 10:33 AM Damn, ok thanks for that.
Thought it might come to that but was looking for a neater way.
Oh well.
Cheers
Yet another question - bit random but here we go:
I have to use mappoint 2002 as its the only version that integrates with Visual C++ 6.
Unfortunately the post codes are out of date.
Is there any way to overwrite the data files on the mappoint 2002 version with the 2006 version for instance. I have tried - all file names are the same - sizes are obviously different but it doesnt work.
Is it possible (by giving it some other files) or am i stuck with it.
Thanks again for all your help with this, you've been a star. :D
Cheers
PieEater Eric Frost 01-08-2008, 11:19 AM I'm not sure that you have to use MapPoint 2002 ? Or at least I didn't know that.
Do you have a reference as to why you have to use MapPoint 2002 Visual C++ 6 ? I would be curious to know... I thought the API's of MapPoint 2002/2004/2006 were just about identical.
Also, it looks like the Isle of Wight postcodes all begin with PO3 except Freshwater and a few others which are PO4.
See Isle of Wight postcodes - Google Search (http://www.google.com/search?q=Isle+of+Wight+postcodes)
I think just checking the postcode string would be relatively easy and straightforward compared to trying to trying to get something out of MapPoint... there are the reverse geocoding algorithms but I think that leaves you open to lots of potential for error.
Eric | |