Sunday, April 16, 2017

Parsing latitude and longitude from SIM808

Parsing latitude and longitude from SIM808


SIM808 returns longitude and latitude in ddmm.mmmmmm format, you have to convert it to hours to plot it on maps (e.g. Google maps and Apple Maps) for that you have to convert using the formula:

.d=(mm.mmmmm/60)
DD=dd+.d

For example, the output of CGPSINF:
 +CGPSINF: 0,3118.588459,5408.784576,247.176812,20160613183218.000,22,13,0.000000000000


The longitude in the example is 3118.588459 and latitude is 5408.784576.

DD_long = 31+(18.588459/60) = 31.30980765 (for some reason the signal was not correct) so I changed the number to -  31.30980765
DD_lat  =  54+(08.784576/60) = 54.1464096 (for some reason the signal was not correct) so I changed the number to - 54.1464096


                      Example of lat and long plotted on the map


I coded this in python, you can change it to PHP, Java or any language that you are programing

#Get lat
latitude_float = latDegree # data in ddmm.mmmmmm format
latitude_hour = (int(latitude_float/100))*-1;# Getting hour, getting the first two numbers and changing the signal
latitude_hour = latitude_hour-((latitude_float+(latitude_hour*100))/60)#converting min to hour, dd+(ddmm.mmmmmm-dd00.00)/60

#Get lon
longitude_float = lonDegree # data in ddmm.mmmmmm format
longitude_hour = (int(longitude_float/100))*-1;# Getting hour, getting the first two numbers and changing the signal
longitude_hour = longitude_hour-((longitude_float+(longitude_hour*100))/60)#converting min to hour, dd+(ddmm.mmmmmm-dd00.00)/60

2 comments:

  1. thank you dear,

    can you explain more ? how to programming these in your code

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete