Storing GPS data in an SQLite database?

Put problem concerning MapActivities, MapViews, Overlays and GPS in this forum.

Storing GPS data in an SQLite database?

Postby Lordsnoutimus » Thu Mar 04, 2010 9:15 pm

Hi,

This is from another thread, but I am trying desperately to store GPS latitude and longitude data within an SQLite database.


I have created a SQLite database in a separate class to my main activity and I am using this below when the location updates:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.    public void onLocationChanged(Location loc) {
  3.  
  4.         Log.e(TAG, loc.toString());
  5.  
  6.  
  7.  
  8.         ContentValues values = new ContentValues();
  9.  
  10.      
  11.  
  12.         Double lon = loc.getLongitude();
  13.  
  14.         Long time = loc.getTime();
  15.  
  16.         values.put(GPSData.GPSPoint.LONGITUDE, loc.getLongitude());
  17.  
  18.            values.put(GPSData.GPSPoint.LATITUDE, loc.getLatitude());
  19.  
  20.            values.put(GPSData.GPSPoint.TIME, loc.getTime());
  21.  
  22.         getContentResolver().insert(GPSDataContentProvider.CONTENT_URI, values);
  23.  
  24.       }
  25.  
  26.  
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


Apparently this line is throwing an error:
and the Double long and long time are not being read? does this matter?

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. getContentResolver().insert(GPSDataContentProvider.CONTENT_URI, values);
Parsed in 0.030 seconds, using GeSHi 1.0.8.4
Lordsnoutimus
Junior Developer
Junior Developer
 
Posts: 16
Joined: Sat Oct 17, 2009 10:05 am

Top

saving gps location

Postby i_raqz » Sun Mar 21, 2010 11:55 pm

hi..did you find any solution for that? i am trying to save the co-ordinates in an array/file ...actually send it over a socket to some other machine..any suggestions?
Thanks,
raqz
i_raqz
Freshman
Freshman
 
Posts: 8
Joined: Sun Mar 21, 2010 12:26 pm
Location: Pittsburgh

Postby Lordsnoutimus » Mon Mar 22, 2010 1:39 am

Hi i_raqz,

I gave up with the Content Provider in the end. I couldn't find the problem and I didn't actually need to implement a contentprovider as my application doesn't need to share data with another application.

Instead, I created a database:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. public class WaypointsData extends SQLiteOpenHelper {
  3.  
  4.         private static final String DATABASE_NAME = "waypoints.db";
  5.  
  6.         private static final int DATABASE_VERSION = 2;
  7.  
  8.        
  9.  
  10.         //helper object for database
  11.  
  12.         public WaypointsData(Context ctx) {
  13.  
  14.                 super(ctx, DATABASE_NAME, null, DATABASE_VERSION);
  15.  
  16.         }
  17.  
  18.        
  19.  
  20.          @Override
  21.  
  22.            public void onCreate(SQLiteDatabase db) {
  23.  
  24.               db.execSQL("CREATE TABLE " + TABLE_NAME + " (" + _ID
  25.  
  26.                     + " INTEGER PRIMARY KEY AUTOINCREMENT, " + LONGITUDE
  27.  
  28.                     + " INTEGER," + LATITUDE + "  INTEGER," + TIME
  29.  
  30.                     + " INTEGER );");
  31.  
  32.            }
  33.  
  34.  
  35.  
  36.        
  37.  
  38.         @Override
  39.  
  40.         public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
  41.  
  42.         db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
  43.  
  44.         onCreate(db);
  45.  
  46.         }
  47.  
  48.        
  49.  
  50.        
  51.  
  52. }
Parsed in 0.037 seconds, using GeSHi 1.0.8.4


And just used a cursor to retrieve the data I wanted directly:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. private Cursor getWaypoints() {
  2.  
  3.                         SQLiteDatabase db = waypoints.getReadableDatabase();
  4.  
  5.                         Cursor cursor = db.query(TABLE_NAME, FROM, null, null, null, null, ORDER_BY);
  6.  
  7.                         startManagingCursor(cursor);
  8.  
  9.                         return cursor;
  10.  
  11.                 }
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


If you are planning on distributing the GPS coordinates to a webserver or something similar, using a database is probably easier, and then using the Android HTTP class. If you have any more questions about the database, I can help you out.
Lordsnoutimus
Junior Developer
Junior Developer
 
Posts: 16
Joined: Sat Oct 17, 2009 10:05 am

Postby i_raqz » Mon Mar 22, 2010 2:05 am

Hi Lordsnoutimus,

Thanks for the reply. Well, I am trying to send the GPS co-ordinates to my webserver through sockets (not android http - we are on the same side :) ). But I am unable to store the gps co-ordinates in a variable/array/object or anything like that. The app crashes. Could you please tell me how do I save and then send it through the socket.
Please check the below link for then entire code that I wrote. Thanks.

my post on google group
Thanks,
raqz
i_raqz
Freshman
Freshman
 
Posts: 8
Joined: Sun Mar 21, 2010 12:26 pm
Location: Pittsburgh

Top

Return to Map Problems

Who is online

Users browsing this forum: No registered users and 1 guest