سؤال

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 { }
                    })
                    );

            }
هل كانت مفيدة؟

المحلول

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top