Ask Your Question

How to read latitude and longitude information from /GPSFix message in my bagfile?

asked 2013-07-24 18:25:49 -0500

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

Hi friends, i am having a bagfile containing /GPSFix information. i want to read and publish its information using gpsd. for that i used gpsd_client tutorial.

I have given rosbag node port number for gpsd_client otherwise it is showing error. When i run gpsd_client it says "GPSD opened" but my gpsd_subscriber is not printing latitude and longitude information.

Please help me to solve this problem.

This is my gpsd_client

mit@mit-HP-Pro-3330-SFF:~/Desktop/Bagfiles$ rostopic info /GPSFix 
Type: gps_common/GPSFix

Publishers: None

 * /gps_subscriber (<a href="http://mit-HP-Pro-3330-SFF:33912/">http://mit-HP-Pro-3330-SFF:33912/</a>)

mit@mit-HP-Pro-3330-SFF:~/Desktop/Bagfiles$ rosrun gpsd_client gpsd_client _host:=localhost _port:=33912
[ INFO] [1374726241.992697318]: GPSd opened

This is my gpsd_subscriber

 mit@mit-HP-Pro-3330-SFF:~/Desktop/gps_test$ rosrun gpsd_subscriber gpsTest

This is my gpsd_subscriber source code

#include <iostream>
#include <ros/ros.h>
#include <sensor_msgs/NavSatFix.h>
#include <sensor_msgs/NavSatStatus.h>

using namespace sensor_msgs;

void callback(const NavSatFixConstPtr &fix) {

  if (fix->status.status == NavSatStatus::STATUS_NO_FIX) {
    std::cout << "Unable to get a fix on the location." << std::endl;

  std::cout << "Current Latitude: " << fix->latitude << std::endl;
  std::cout << "Current Longitude " << fix->longitude << std::endl;


int main(int argc, char **argv) {
  ros::init(argc, argv, "gps_subscriber");
  ros::NodeHandle nh;

  ros::Subscriber gps_sub = nh.subscribe("/GPSFix", 1, callback);

  return 0;
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2013-07-24 20:48:30 -0500

updated 2013-07-24 20:52:00 -0500

I am afraid the thing you trying to accomplish is not implemented.

gpsd_client can only receive data from gpsd daemon and cannot send data back to it.

The typical scheme to work with GPSd is as follows:

GPS device -> GPSd -> gpsd_client -> ROS message callback

The one you have explained is:

rosbag -> /dev/null

GPSd -> gpsd_client -> ROS message callback

Thus you have two parallel data streams not connected to each other, even more, GPSd has no source of data at all and that is why you receive nothing in callback.

All you have to do is simply subscribe to a topic broadcasted by rosbag without all these GPSd and gpsd_client.


Additionally, if you ran rosbag together with gpsd_client they may interfere while publishing to the same topic.

edit flag offensive delete link more


thank you Boris. . .

Bindu gravatar image Bindu  ( 2013-07-24 21:05:15 -0500 )edit

i need to import this latitude and longitude information to my c++ program . how can i do that? please help

Bindu gravatar image Bindu  ( 2013-07-31 00:22:50 -0500 )edit

You have to use ros::Subscriber and subscribe to your GPS topic. Please go through [beginner tutorials]( to see how to write subscriber in C++.

Boris gravatar image Boris  ( 2013-07-31 01:49:42 -0500 )edit

Dose anyone know how to get the track message from gpsd_client?

weiy1991 gravatar image weiy1991  ( 2015-09-07 08:39:59 -0500 )edit

answered 2013-07-31 19:33:42 -0500

Bindu gravatar image

updated 2013-07-31 19:47:57 -0500

thank you so much, i can read my latitude and longitude info by subscribing to GPS topic. For this only i tried.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2013-07-24 18:25:49 -0500

Seen: 1,426 times

Last updated: Oct 07 '13