Using the OCX from VC++

Use the .tlb with Class wizard automation.

Sample 1

Using easting and northing on a certain roundabout...

ILED_OSGB_POS i;
i.CreateDispatch("LED_OSGB_POS.Application");
i.Convert1(484000, 235550);
double lat1 = i.GetLatitude();
double long1 = i.GetLongitude();

Sample 2

Using grid reference...

ILED_OSGB_POS i;
i.CreateDispatch("LED_OSGB_POS.Application");
i.Convert("SP 84000 35550");
double lat1 = i.GetLatitude();
double long1 = i.GetLongitude();

Sample 3

Used to generate pushpins. The instantiated class installations_ contains an array of certain installations sited by various roads in the UK. 

///////////////////////////////////////////////////////////////////////////////
void CAdoDlg::OnButtonMp() 
///////////////////////////////////////////////////////////////////////////////
{
    if (mp_.m_lpDispatch == NULL)
    {
        mp_.CreateDispatch("MapPoint.Application");
        mp_.SetVisible(true); // false gets you a 1/3 speed advantage.
    }

    ILED_OSGB_POS i;
    i.CreateDispatch("LED_OSGB_POS.Application");

    MP_Map mp = mp_.GetActiveMap();

    for (int x = 1; x < 400; x++)
    {
        road_location rl;
        if (installations_.get_location(x, rl))
        { 
            i.Convert1(rl.get_easting(), rl.get_northing()); 
            double lat = i.GetLatitude();
            double longi = i.GetLongitude();

            MP_Location loc = mp.GetLocation(lat, longi, 0.0);
            CString szTemp;
            szTemp.Format("%d", x);
            Pushpin pp = mp.AddPushpin(loc, szTemp);
            pp.SetSymbol(21);
        }
    }
    mp_.DetachDispatch();
}

Sample 4

How to zoom the map! This example shows how to pass variant arrays over to MapPoint. (OK, nothing to do with the OCX, but it's such a pain to do: it's here for reference.)

This uses the MapPoint Union method, with 2 points near the 52N 0W confluence.

///////////////////////////////////////////////////////////////////////////////
void CAdoDlg::OnButtonMpZoom() 
///////////////////////////////////////////////////////////////////////////////
{
    if (mp_.m_lpDispatch == NULL)
    {
        if (!mp_.CreateDispatch("MapPoint.Application"))
            return;
    }

    VARIANT arr;
    arr.vt = VT_ARRAY | VT_VARIANT;
    arr.parray = NULL;

    try
    {
        mp_.SetVisible(true);
        mp_.SetUserControl(false);

        MP_Map m = mp_.GetActiveMap();
        MP_Location loc1 = m.GetLocation(52.0, -0.05, 0.0);
        MP_Location loc2 = m.GetLocation(52.0,  0.05, 0.0);

        SAFEARRAYBOUND bound = { 2, 0 }; // 2 elements, starting at 0
        arr.parray = SafeArrayCreate (VT_UNKNOWN, 1, &bound);
        long rgIndex = 0; 
        VERIFY(SafeArrayPutElement(arr.parray, &rgIndex, loc1) == S_OK);
        rgIndex ++;
        VERIFY(SafeArrayPutElement(arr.parray, &rgIndex, loc2) == S_OK);

        MP_Location loc3 = m.Union(arr);
        loc3.GoTo();
    }
    catch (COleDispatchException* e)
    {
        e->Delete();
    }
    catch (COleException* e)
    {
        e->Delete();
    }
    if (arr.parray)
        SafeArrayDestroy(arr.parray);
    mp_.DetachDispatch();
}

Embedded MFC sample

Back to the Mapping page