dimanche 1 novembre 2015

SQLite database implementation in a maps application

i am currently writing an google map application using the google maps API i have followed the tutorial of google and have managed to get a certain map to be displayed the class for map is in map_activity.java

package com.test.android.mappy;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import com.google.android.gms.maps.*;
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_maps);
        MapFragment mapFragment = (MapFragment) getFragmentManager()
                .findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);
    }

    @Override
    public void onMapReady(GoogleMap map) {
        // Add a marker in Paramaribo, Suriname, and move the camera.
        LatLng paramaribo = new LatLng(5.87, -55.17);
        map.addMarker(new MarkerOptions().position(paramaribo).title("Marker in Paramaribo"));
        map.moveCamera(CameraUpdateFactory.newLatLng(paramaribo));
    }
}

i'm also trying to implement an SQLite database that will be used to save locations to do this i implemented a class for this in offlinedata.java

package com.test.android.mappy;

import android.content.Context;
import android.database.sqlite.*;

public class OfflineData extends SQLiteOpenHelper {
    private static final String DATABASE_NAME="MAP_DATA";
    private static final int DATABASE_VERSION = 1;
    private static final String LOCATION_TABLE_NAME = "LocationInformation";
    private static final String LOCATION_TABLE_CREATE =
            "CREATE_TABLE"+LOCATION_TABLE_NAME+
                    "( id integer primary key"+
                    "Place name text"+
                    "Category text"+
                    "Address text"+
                    "Latitude integer, "+
                    "Longitude int);";
    OfflineData (Context context){//constructor
        super(context,DATABASE_NAME,null,DATABASE_VERSION);
    }
    @Override
    public void onCreate(SQLiteDatabase db){
        db.execSQL(LOCATION_TABLE_CREATE);
    }
    public void onUpgrade(SQLiteDatabase db,int OldVersion,int NewVersion){
        /*db.execSQL("CREATE TABLE new_test_table (COL_A, COL_B, COL_C,COL_D);" +
                   "INSERT INTO new_test_table SELECT * FROM test_table;" +
                   "DROP TABLE test_table;" +
                   "ALTER TABLE new_test_table RENAME TO test_table;");*/
    }
}

my questions is how do i connect these two classes so that i can verify that my code is correct do i need an another file to do this? Or will Offlinedata.java run without connecting these two classes? and where will the database be saved? the internal or external memory?

Aucun commentaire:

Enregistrer un commentaire