C# GPS在谷歌地图上给出了错误的位置
当我将C# GPS在谷歌地图上给出了错误的位置,c#,wpf,gps,windows-mobile-gps,gpsd,C#,Wpf,Gps,Windows Mobile Gps,Gpsd,当我将
的GPS与谷歌地图API
连接到
我的C#代码给出了离出口位置约1公里的错误位置,但当我使用以下代码时,它给出了10米内的出口位置,我使用了以下一组gps坐标代码,并将其传递给web浏览器
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 { }
})
);
}
我认为问题在于你把秒转换成度
latt += double.Parse(lat.Substring(5)) / 3600.0/100.0;
只需将“秒”部分除以3600即可
latt += double.Parse(lat.Substring(5)) / 3600.0;
lonn += double.Parse(lon.Substring(6)) / 3600.0;
另一件事你可能已经知道,纬度值是负的,如果它在南边,经度值在西边是负的。否则,您的位置可能会显示在地球的错误一侧。不知道如何精确定位GPS位置…该位置位于右侧,但已从当前位置移开,且位置位于N和E。。最后一部分是第二个圆格式,需要将其除以100,否则它开始连续指向不同的位置(度=分/60)和(分=秒/60)。因此(度=(秒/60)/60)或(度=秒/3600)。如果你这样做(度=秒/3600/100),这意味着(度=秒/360000)哪个偏离路线会给出错误的值。试着用3600除以秒部分,然后检查。作为参考,我发现这个老问题是如此