0

I have an android google maps app which is to record the location and magnetometer readings and display those values, and save to a file for later viewing in google maps in a browser.

What format should they be saved in and is there an API for creating such a file?

PerceptualRobotics
  • 422
  • 1
  • 3
  • 18

2 Answers2

0

In Android, there are plenty of ways to save data, but a good way to do so is by using Shared Preferences. SharedPreferences stores data in Key-Value pairs and from what I understand from your explanation, all the data you are trying to store should fit the criteria.

To access information stored in a file using SharedPreferences you have to call a method getSharedPreferences(String name, int mode). For details/tutorial on how to use this method, visit this link. And the official documentation for SharedPrefences can be found here.

Hope this helps.

pointNclick
  • 1,584
  • 1
  • 12
  • 17
  • Is that format recognised by google maps as a set of latitude/longtitude points, along with associated magnetic field values? – PerceptualRobotics Jan 03 '15 at 12:37
  • Yes, Of course! In fact it is one of the recommended ways to store that info. For clarification, take a look at [this](http://stackoverflow.com/questions/3604849/where-to-save-android-gps-latitude-longitude-points). – pointNclick Jan 05 '15 at 18:51
0

An easy way that I implemented is savaing the data first in a in lists and then in a SQLite database:

if (db != null) {
    for (int x = 0; x < latitud.size(); x++) {
    newReg.put("ID", x);
    newReg.put("Latitude", latitude.get(x));
    newReg.put("Longitude", longitude.get(x));
    db.insert("Records", null, newReg);
}
} else{
    Toast.makeText(MainActivity.this, "Error",Toast.LENGTH_SHORT).show();
  }
db.close();

private void getLatLgns() {

DBConnection dbc = new DBConnection(this, "MapsDB", null, 1); 
SQLiteDatabase db = dbc.getWritableDatabase();

Cursor c = db.rawQuery("SELECT Latitude,Longitude from Records", null);
if(c.moveToFirst()){ 
    do {
        allLatLng.add(new LatLng(Double.parseDouble(c.getString(0)), Double.parseDouble(c.getString(1))));
    }while (c.moveToNext());
}
db.close();

}

If you don't know how to use SQLite just look for some info on internet, is pretty easy and there's a lot of examples.

Brandon Zamudio
  • 2,853
  • 4
  • 18
  • 34