I'm trying to get data from a bluetooth gps device connected to my Android 2.3 tablet. At the moment I'm able to pair it using Android bluetooth stack and to read from the serial device that has been created. Now I've a lot of NMEA data coming from the gps...I've tried to integrate a little piece of java code to parse this strings but I'd like to know if there is something similar already available in the Android framework. All I need to know is latitute/longitude and compass direction. Thank you!
Asked
Active
Viewed 3,751 times
1 Answers
3
Not sure if anything exists, in any case if you just want the position you probably just need to parse the RMC sentences, see http://www.gpsinformation.org/dale/nmea.htm#RMC
A simple example of Java code to do that:
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);
}
related question: Parsing GPS receiver output via regex in Python
-
Yes this is what I'm doing now :-), I was hoping for a parser already implemented in Android. Otherwise I will go this way. Thank you. – mrAlmond Nov 22 '12 at 11:20
-
You have probably already tried [Java Marine](http://marineapi.sourceforge.net/). I don't know if it mature enough ; the project does not seem to be very active. – Stéphane Nov 22 '12 at 22:03
-
No I haven't tried it but it worth a look for sure. Thank you for the suggestion. – mrAlmond Nov 23 '12 at 07:57