我正在尝试从连接到我的Android 2.3平板电脑的蓝牙GPS设备获取数据。 目前我可以使用Android蓝牙堆栈配对,并从已创建的串行设备读取。 现在我有很多来自gps的NMEA数据...我试图整合一小段java代码来解析这些字符串,但我想知道Android框架中是否有类似的东西可用。所有我需要知道的是latitute /经度和指南针方向。谢谢!
答案 0 :(得分:3)
不确定是否存在任何内容,无论如何只要您想要解析RMC句子所需的位置,请参阅http://www.gpsinformation.org/dale/nmea.htm#RMC
一个简单的Java代码示例:
final String sentence = "$GPRMC,123519,A,4807.038,N,01131.000,E,022.4,084.4,230394,003.1,W*6A";
if (sentence.startsWith("$GPRMC")) {
String[] strValues = sentence.split(",");
double latitude = Double.parseDouble(strValues[3])*.01;
if (strValues[4].charAt(0) == 'S') {
latitude = -latitude;
}
double longitude = Double.parseDouble(strValues[5])*.01;
if (strValues[6].charAt(0) == 'W') {
longitude = -longitude;
}
double course = Double.parseDouble(strValues[8]);
System.out.println("latitude="+latitude+" ; longitude="+longitude+" ; course = "+course);
}