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;
}