Re: [OpenMap Users] Issue with nmea/kml conversion

From: JR Andreassen <janrune_at_io.com>
Date: Mon, 06 Jul 2009 13:47:20 -0500

Here is some C++ code that does what you're trying to do...
readNMEAString is what you want to look at, the rest is for illustration
of call strings

// ---------------------------------------------------------------------
    /**
    * ReadNMEA
    * _at_param nmeastring -> HH{H}MM.ss{sss}
    * _at_param fmstr -> "%{2|3}d%2d.%d"
    * _at_param direction -> Compas direction
    * _at_param negatedir -> Compas direction to use as negacive Direction
    */
    double GPS_Record::readNMEAString(const char* nmeastring, const
char* fmstr, const char* direction, const char negatedir)
    {
        double retVal = 0.0;
        if(nmeastring != NULL && direction != NULL)
        {
            LatLonPoint point;
            if(sscanf(nmeastring, fmstr, &point.hours, &point.seconds)
== 2)
            {
                point.minutes = static_cast<int>(point.seconds);
                point.seconds = (point.seconds - point.minutes) *60;
                retVal = toLatLongValue(point);
                if(toupper(*direction) == negatedir)
                {retVal = -retVal; }
            }
        }
        return retVal;
    }
// ---------------------------------------------------------------------
// ---------------------------------------------------------------------
    /**
    * Set Latitude
    * _at_param nmeastring -> HHMM.ss{sss}
    * _at_param direction -> N/S
    */
    bool GPS_Record::setLatitude_NMEA(const char* nmeastring, const
char* direction)
    {
        bool retVal = false;
// double val = readNMEAString(nmeastring, "%2d%2d.%d",
direction, 'S');
        double val = readNMEAString(nmeastring, "%2d%f", direction, 'S');
        vdLattitude.setValue(val);
        if(val != 0.0)
        { retVal = true;}
        return retVal;
    }
// ---------------------------------------------------------------------
    /**
    * Set Longitude
    * _at_param nmeastring -> HHHMM.ss{sss}
    * _at_param direction -> E/W
    */
    bool GPS_Record::setLongitude_NMEA(const char* nmeastring, const
char* direction)
    {
        bool retVal = false;
// double val = readNMEAString(nmeastring, "%3d%2d.%d",
direction, 'W');
        double val = readNMEAString(nmeastring, "%3d%f", direction, 'W');
        vdLongitude.setValue(val);
        if(val != 0.0)
        { retVal = true;}
        return retVal;
    }
// ---------------------------------------------------------------------
/**
 * GLL - Geographic position, Latitude and Longitude
        GLL,4916.45,N,12311.12,W,225444,A
           4916.46,N Latitude 49 deg. 16.45 min. North
           12311.12,W Longitude 123 deg. 11.12 min. West
           225444 Fix taken at 22:54:44 UTC
           A Data valid
             (Garmin 65 does not include time and status)
*/

bool NMEA_0183::parse_GLL(const char
elems[][NMEA_SCENTENCE_MAX_ELEMENTS], GPS_Record& target)
{
    bool retVal = target.setLatitude_NMEA(elems[1], elems[2]);
    retVal = retVal && target.setLongitude_NMEA(elems[3], elems[4]);
    retVal = retVal && target.setDateTime(NULL, elems[5]);
    return retVal;
}


Mulone wrote:
> Hi everybody,
>
> I’m still messing with gps on openmap.
> When I convert a GPGLL message (containing DMS coordinates) to decimal
> degrees I get a point pretty close to the right one but still wrong, while
> if I load the same message into a nmea2kml converter (such as
> http://www.h-schmidt.net/NMEA ), I get exactly the right coordinates. So I’m
> missing something in the conversion. I’m just converting the dms value (e.g.
> 5318.56460 -> 53* 18’ 56,46'' -> 53.31568), what else do I need to do to get
> the right position?
>
> E.g.
>
> INPUT Nmea message $GPGLL,5318.56460,N,00613.46033,W,110812.000,A,A*48
> OUTPUT My app: user position: 53.31568 -6.2294536 (wrong)
> OUTPUT Kml converter: <coordinates>-6.22434117,53.30940850,40</coordinates>
> (correct)
>
> INPUT Nmea message $GPGLL,5318.56451,N,00613.46047,W,110814.000,A,A*4F
> OUTPUT My app: user position: 53.31568 -6.2294574 (wrong)
> OUTPUT Kml converter: <coordinates>-6.22434117,53.30940850,40</coordinates>
> (correct)
>

--
[To unsubscribe to this list send an email to "majdart_at_bbn.com"
with the following text in the BODY of the message "unsubscribe openmap-users"]
Received on Mon Jul 06 2009 - 14:48:05 EDT

This archive was generated by hypermail 2.3.0 : Tue Mar 28 2017 - 23:25:09 EDT