sburgues
Posts: 2
Joined: Sat Sep 03, 2011 11:53 pm
Location: Uruguay

Convert coordinates to NMEA

Sat Sep 03, 2011 11:54 pm

Johan, hi.

We are facing some trouble when trying to convert coordinates from one format to another.
After hours of searching for information on the internet we gave up, so here we are asking you for help.

We receive coordinates from a GPS tracker and we need to convert them to the NMEA format in order to use the FRPOS command to send location updates to GpsGate Server.

Here are some samples of what we receive:

Latitude: -56.529176
Longitude: -33.386666

Is this decimal format?
What formula shall we use in order to convert them?

Thanks in advance

User avatar
johan
GpsGate
Posts: 14089
Joined: Wed Aug 04, 2004 10:40 pm
Location: Sweden
Contact: Website

RE: Convert coordinates to NMEA

Mon Sep 05, 2011 12:33 pm

The format you have is "decimal degrees". You want to convert it to Degrees + Minutes. And then use the format DDDMM.mmmmm where "DDD" is the number of degrees, MM is the integer part of number of minutes, and "mmmmm" the fractional part of minutes.

There are 60 minutes on each degree. (Minutes has nothing to do with time, "minutes" means to divide in 60 parts in this case)

For latitude you have 56 degrees. Then simply multiply the fractional part with 60 to get the minutes. 60 * 0.529176 = 31.75057

This means the NMEA format will be 5631.75057
And since the Latitude is negative it is the southern hemisphere - 5631.75057,S
A positive number would be the northern hemisphere "N"

For longitude you have 33 degrees. Then simply multiply the fractional part with 60 to get the minutes. 60 * 0.386666 = 23.19997

This means the NMEA format will be 3323.19997
And since the Longitude is negative it is the western hemisphere - 3323.19997,W
A positive decimal degree would be the eastern hemisphere "E"

When covering numbers to string, be careful about the decimal sign, it should always be "." and not ","

Regards,
Johan

GpsGate Support

sburgues
Posts: 2
Joined: Sat Sep 03, 2011 11:53 pm
Location: Uruguay

RE: Convert coordinates to NMEA

Mon Sep 05, 2011 7:29 pm

Johan, thanks for your response.

One more question:

If the int part of minutes had 1 digit instead of 2, shall we add the 0 before?
For example:

If latitude was: 3.162203
Minutes would be: 0.162203 * 60 = 9.73218

Then, the final result would be 39.73218,N or 309.73218,N?

Same doubt applies to the degrees part: 309.73218,N or 0309.73218,N?

User avatar
johan
GpsGate
Posts: 14089
Joined: Wed Aug 04, 2004 10:40 pm
Location: Sweden
Contact: Website

RE: Convert coordinates to NMEA

Mon Sep 05, 2011 8:53 pm

> If the int part of minutes had 1 digit instead of 2, shall we add the 0 before?

Yes.

> Same doubt applies to the degrees part: 309.73218,N or 0309.73218,N?

both are ok.

Regards,
Johan

GpsGate Support

shaminda
Posts: 18
Joined: Fri Apr 26, 2013 11:35 am
Location: Sri Lanka

RE: Convert coordinates to NMEA

Wed Aug 21, 2013 2:29 pm

Hi,

I was trying to implement "convert coordinates to NMEA" which we are planing to use on a Windows Phone 8 application,Which will send data to gpsgate server. Can anyone share sample code to convert coordinates to NMEA format.

Thanks
Shaminda

kalmangabriel
Posts: 373
Joined: Wed Feb 25, 2009 12:36 am
Location: Romania
Contact: Website

RE: Convert coordinates to NMEA

Wed Aug 21, 2013 6:48 pm

@shaminda define "coordinates"...

<font color="red">Please note that my reply IS NOT from GpsGate!!!</font id="red">
------------------------------------------
<font size="1">Email: tech@scorpiontrack.ro Skype: gabrielkalman
Internet: It doesn't make you more stupid, it just makes your stupidity more accessible to others</font id="size1">

shaminda
Posts: 18
Joined: Fri Apr 26, 2013 11:35 am
Location: Sri Lanka

RE: Convert coordinates to NMEA

Wed Aug 21, 2013 9:12 pm

Hi,

I need to convert decimal degrees to DDMM.mmmmm NMEA format without using gpsgate SDK (GpsGate.Client.dll), as I can't use it on Windows Phone 8 application (.NET 4)

example:
Longitude : 80.84506 -----> 08050.7036,E
Latitude : 8.16126666666667 -----> 0809.6760,N

Thanks
Shaminda

kalmangabriel
Posts: 373
Joined: Wed Feb 25, 2009 12:36 am
Location: Romania
Contact: Website

RE: Convert coordinates to NMEA

Fri Aug 23, 2013 4:34 pm

private string DD2NMEA(double lat, double lng)
{
string nmea = "";
double lata = Math.Abs(lat);
double latd = Math.Truncate(lata);
double latm = (lata - latd) * 60;
string lath = lat > 0 ? "N" : "S";
double lnga = Math.Abs(lng);
double lngd = Math.Truncate(lnga);
double lngm = (lnga - lngd) * 60;
string lngh = lng > 0 ? "E" : "W";

nmea += latd.ToString("00") + latm.ToString("00.00000") + "," + lath + ",";
nmea += lngd.ToString("000") + lngm.ToString("00.00000") + "," + lngh;

return nmea;
}

<font color="red">Please note that my reply IS NOT from GpsGate!!!</font id="red">
------------------------------------------
<font size="1">Email: tech@scorpiontrack.ro Skype: gabrielkalman
Internet: It doesn't make you more stupid, it just makes your stupidity more accessible to others</font id="size1">

shaminda
Posts: 18
Joined: Fri Apr 26, 2013 11:35 am
Location: Sri Lanka

RE: Convert coordinates to NMEA

Mon Oct 14, 2013 8:46 am

Hi Kalmangabriel,

Thanks, appreciate your support.

Thanks
Shaminda

Return to “GpsGate for Developers”