Normalizing decimal degree coordinates
NormalizeDD.cpp
// Copyright 2010 ESRI
// 
// All rights reserved under the copyright laws of the United States
// and applicable international laws, treaties, and conventions.
// 
// You may freely redistribute and use this sample code, with or
// without modification, provided you include the original copyright
// notice and use restrictions.
// 
// See the use restrictions.
// 


#include <stdio.h>
#include <ArcSDK.h>
#include <olb/esridefensesolutions.h>

#if defined(ESRI_UNIX)
    // implemented in libDefenseSolutionsSDK.so
    void DsInitialize();
#endif

int main (int argc, char **argv)
{
    USES_CONVERSION;

    ::AoInitialize (NULL);
#if defined(ESRI_UNIX)
    ::DsInitialize();
#endif
    {
        IAoInitializePtr ipInit (CLSID_AoInitialize);
        esriLicenseStatus status;
        ipInit->Initialize (esriLicenseProductCodeEngine, &status);
        if ( status != esriLicenseCheckedOut )
        {
            printf ("Invalid Licensing.\n");
            ::AoUninitialize();
            AoExit (0);
        }
    }

    // Sample:  input a geolocation in a couple of ways, get back normalized strings and display them
    ICoordinatePtr  ipCoord          (CLSID_DDCoordinate);
    const char     *ddInputString    ("S12 E10");
    const double    inputX           (10);
    const double    inputY           (-12);
    CComBSTR        normalizedString;

    // put binary geographic coordiantes into the converter
    ipCoord->PutCoords (inputX, inputY);

    // get coordinates formatted as a normalized string
    ipCoord->get_String (&normalizedString);
    printf ("input = (%f, %f), DD normalized string = '%s'\n", inputX, inputY, OLE2A(normalizedString));

    // convert an input coordinate string into a normalized string
    ipCoord->put_String (CComBSTR(ddInputString));
    normalizedString.Empty();
    ipCoord->get_String (&normalizedString);
    printf ("input = '%s', DD normalized string = '%s'\n", ddInputString, OLE2A(normalizedString));

    return 0;

    // results:
    // input = (10.000000, -12.000000), DD normalized string = '12.00S 010.00E'
    // input = 'S12 E10', DD normalized string = '12.00S 010.00E'
}