0

i'm using the GPS of the Sim548c with the Google map API when i connect it to the my C# code it gives the Wrong location about 1KM away from the Exit location but when i used the following software it gives the exit location with in a 10m i used the following set of code for the gps cordinats and pass it to the web broswers.

if (s.Contains("$GPRMC"))
        {
            latlon = s.Split('*');
            int i=0;
            while (!latlon[i].Contains("GPRMC"))
            {
                i++;
            }
            //latlon = latlon[i].Split(',');
            if (latlon[i].Contains(",A,"))
            {
                latlon = latlon[i].Split(',');
                lat = latlon[3];
                lon = latlon[5];



                latt = double.Parse(lat.Substring(0,2));
                latt += double.Parse(lat.Substring(2, 2)) / 60.0;
                latt += double.Parse(lat.Substring(5)) / 3600.0/100.0;
                lonn = double.Parse(lon.Substring(0,3));
                lonn += double.Parse(lon.Substring(3, 2))/60.0;
                lonn += double.Parse(lon.Substring(6))/3600.0/100.0;


                //richTextBox1.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate() { richTextBox1.AppendText("Write\n"); }));
                richTextBox2.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate() 
                    { 
                        richTextBox2.AppendText(lonn.ToString()+","+latt.ToString()+"\n"); 
                    }));
                label1.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate()
                {
                    label1.Content = lon;
                }));
                label2.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate()
                {
                    label2.Content = lat;
                }));
                Thread.Sleep(1000);
                webBrowser1.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate()
                    {
                        try
                        {
                            webBrowser1.InvokeScript("animate", latt.ToString(), lonn.ToString());
                        }
                        catch { }
                    })
                    );

            }
Muhammad Nauman
  • 213
  • 1
  • 4
  • 20

1 Answers1

1

I think the problem is there where you convert seconds to degrees

latt += double.Parse(lat.Substring(5)) / 3600.0/100.0;

You only need to divide the 'seconds' part with 3600

latt += double.Parse(lat.Substring(5)) / 3600.0;
lonn += double.Parse(lon.Substring(6)) / 3600.0;

Another thing you might already know that the latitude value is negative if it's on southern side and longitude value is negative on the western side. Otherwise your location may appear on the wrong side of the globe.

ABH
  • 3,391
  • 23
  • 26
  • the location is on the right side but moved away from the current location and the location is in N and E .. the last portion is of second in round format and required to divide it by 100 else it start pointing in different location continuously – Muhammad Nauman May 06 '12 at 06:59
  • (Degrees = Minutes / 60) and (Minutes = Seconds / 60).Therefore (Degrees = (Seconds / 60) / 60) or (Degrees = Seconds / 3600). If you do (Degrees = Seconds / 3600 / 100) it means (Degrees = Seconds / 360000) which off-course will give the wrong value. Try dividing the Seconds part only with 3600 and then check. – ABH May 06 '12 at 07:21
  • for reference i have found this older question on SO http://stackoverflow.com/questions/3249700/convert-degrees-minutes-seconds-to-decimal-coordinates – ABH May 06 '12 at 07:24