Firstly I would convert OSM to a shapefile, it makes it easier to use and protects against 'black spots'.
Here's a bit of code to get you started:
// GDALAllRegister(); // More recent versions don't separate OGR from GDAL
// READ http://www.gdal.org/ogr_apitut.html FOR MORE INFO
char* BasePath = ""; // FILL IN FULL PATH TO SHAPE FILE
OGRDataSource *hDS = NULL;
OGRSFDriver *Driver = NULL;
hDS = OGRSFDriverRegistrar::Open(BasePath,FALSE,&Driver);
OGRLayer *Layer = hDS->GetLayerByName("Polyline");
OGRSpatialReference* LayerSR = Layer->GetSpatialRef();
OGRSpatialReference WGS84 = OGRSpatialReference(0);
WGS84.importFromEPSG(4326);// THIS IS WHERE EPSG: NUMBERS COME IN HANDY
// create a query geometry, YourX, YourY need to be in the same spatial reference
// as the osm data. This limits the features returned to just the ones near the X,Y
OGRGeometry* QueryGeom = pt.Buffer(SutableDistance); // make a buffer of the point
// now the layer will only return intersecting features..
Layer->ResetReading(); // initialize
int pCnt = Layer->GetFeatureCount();
if (pCnt > 0)
while ((pFeat = Layer->GetNextFeature()) != NULL)
OGRGeometry* pGeom = pFeat->GetGeometryRef(); // get the geometry for the feature..
pGeom->transformTo(&WGS84);// Now the geometry is in WGS84
// READ http://stackoverflow.com/questions/18747370/how-to-extract-vertexes-of-geometries-in-esri-shapefiles-using-ogr-library-with
// ABOUT GETTING THE 'NODES' IN THIS LINE
After you have broken down the line into vertices it's pythagorean to find the closest vertex. You need to know which way you're headed to decide what the next one is (with the line direction or against it)... to get sensible distances you would need to project both points to a projected coordinate system like UTM, Lamberts or Albers.. the parameters for these depend on where you are but a mathematical formula can decide which parameters is most appropriate.