Author 
Topic 

sburgues
New Member
Uruguay
2 Posts 
Posted  09/03/2011 : 14:54:41

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 

johan
Forum Admin
Sweden
15389 Posts 
Posted  09/05/2011 : 03:33:50

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
New Member
Uruguay
2 Posts 
Posted  09/05/2011 : 10:29:19

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? 


johan
Forum Admin
Sweden
15389 Posts 
Posted  09/05/2011 : 11:53:50

> 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
Junior Member
Sri Lanka
19 Posts 
Posted  08/21/2013 : 05:29:23

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
Senior Member
Romania
376 Posts 
Posted  08/21/2013 : 09:48:30

@shaminda define "coordinates"...
Please note that my reply IS NOT from GpsGate!!!  Email: tech@scorpiontrack.ro Skype: gabrielkalman Internet: It doesn't make you more stupid, it just makes your stupidity more accessible to others 


shaminda
Junior Member
Sri Lanka
19 Posts 
Posted  08/21/2013 : 12:12:29

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
Senior Member
Romania
376 Posts 
Posted  08/23/2013 : 07:34:57

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; }
Please note that my reply IS NOT from GpsGate!!!  Email: tech@scorpiontrack.ro Skype: gabrielkalman Internet: It doesn't make you more stupid, it just makes your stupidity more accessible to others 


shaminda
Junior Member
Sri Lanka
19 Posts 
Posted  10/13/2013 : 23:46:10

Hi Kalmangabriel,
Thanks, appreciate your support.
Thanks Shaminda 



Topic 
