Search code examples
androidbluetoothgpsandroid-2.3-gingerbreadnmea

Parse NMEA data in Android 2.3


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!


Solution

  • 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