Jacek
Jacek

Reputation: 45

How to retrieve data from GPSD and use them in Android Client


I have to make Android client who will be showing car position in Google maps. the vehicle has a Raspberry installed on board. I have seen some applications to show GPSD data as NMEA form, but it's not enough for me.

I make some review about buffering data from GPSD daemon. Oracle supports java ME to share data into client, but does anyone know if exists any alternative?

Could You tell me what is the best way to retrieve this data and use them in google Maps Api (or the best protocol to get data from Android Daemon)? Thanks for any help :)

Upvotes: 0

Views: 1296

Answers (1)

pas6vite
pas6vite

Reputation: 11

One solution is to implement a GPSD client in your Android App. For that you can use for example this JAVA lib. https://github.com/ivkos/gpsd4j

Then you just need to know the IP address of the GPSD server installed on the Raspberry Pi and configure your client.

Below an example, showing how to instanciate the GPSD client and retrieve Gps data

    GpsdClientOptions options = new GpsdClientOptions()
        .setReconnectOnDisconnect(true)
        .setConnectTimeout(3000) // ms
        .setIdleTimeout(30) // seconds
        .setReconnectAttempts(5)
        .setReconnectInterval(3000); // ms
    GpsdClient client = new GpsdClient("192.168.43.213", 2947, options);
    // Adds a message handler that handles incoming TPV messages
    client.addHandler(TPVReport.class, tpv -> {
        Double lat = tpv.getLatitude();
        Double lon = tpv.getLongitude();
        Double altitude = tpv.getAltitude();
        Double speed =tpv.getSpeed();

        logger.info("Latitude= "+lat+" Longitude="+lon+" Altitude="+altitude+" Speed="+speed);
    });

    client.start();
    client.watch();

Hope it will help.

Upvotes: 1

Related Questions