如何获得桌面应用程序的经度和经度?

时间:2012-05-04 04:01:44

标签: c# .net

我可以在Windows 7桌面应用程序上获得经纬度吗?

通常它可以在使用GPS,3G或WiFi的手机或平板电脑上运行。

但我如何使用c#获取坐标?

1 个答案:

答案 0 :(得分:3)

标准GPS设备(内部或外部)在串行端口上发送数据。从Serial Port接收任何数据非常容易。请check this link

    //define serial port
    SerialPort serialPort1 = new SerialPort();

    //configuring the serial port
    serialPort1.PortName="COM1";
    serialPort1.BaudRate=9600;
    serialPort1.DataBits=8;
    serialPort1.Parity=Parity.None;
    serialPort1.StopBits= StopBits.One;

   //read data from serial port
   string data = serialPort1.ReadExisting();

GPS数据由NMEA协议组成。数据本身只是ascii文本,可以扩展到多个句子,例如

  • GGA
  • GSA
  • GSV
  • RMC

以下wikipedia的示例数据。

$GPGGA,092750.000,5321.6802,N,00630.3372,W,1,8,1.03,61.7,M,55.2,M,,*76
$GPGSA,A,3,10,07,05,02,29,04,08,13,,,,,1.72,1.03,1.38*0A
$GPGSV,3,1,11,10,63,137,17,07,61,098,15,05,59,290,20,08,54,157,30*70
$GPGSV,3,2,11,02,39,223,19,13,28,070,17,26,23,252,,04,14,186,14*79
$GPGSV,3,3,11,29,09,301,24,16,09,020,,36,,,*76
$GPRMC,092750.000,A,5321.6802,N,00630.3372,W,0.02,31.66,280511,,,A*43

您可以用于位置数据(纬度/经度)的相应字符串是RMC。

$GPRMC,092750.000,A,5321.6802,N,00630.3372,W,0.02,31.66,280511,,,A*43

其信息描述为here

$GPRMC,225446,A,4916.45,N,12311.12,W,000.5,054.7,191194,020.3,E*68


       225446       Time of fix 22:54:46 UTC
       A            Navigation receiver warning A = OK, V = warning
       4916.45,N    Latitude 49 deg. 16.45 min North
       12311.12,W   Longitude 123 deg. 11.12 min West
       000.5        Speed over ground, Knots
       054.7        Course Made Good, True
       191194       Date of fix  19 November 1994
       020.3,E      Magnetic variation 20.3 deg East
       *68          mandatory checksum

对于完整的GPS数据解析,您可以check this link。希望它会有所帮助。