Storing and retrieving locations in SQLite from Google Maps Android API V2

April 23, 2013
By

In this article, we will develop an Android application which demonstrates how to store and retrieve Google Maps locations in SQLite database from Google Maps Android API V2.



On taping a location in the Google Map, a marker will be drawn at the taped location and the corresponding coordinates with Google Map zoom level will be saved in SQLite database. On restarting the application, the saved locations are retrieved from the SQLite database and redrawn in the Google Maps.



In this application, the database is accessed via Content Providers. The insertion and deletion operations are executed in non-ui thread using AsyncTask objects and the data retrieval is done using CursorLoader.

This application is developed in Eclipse (4.2.1) with ADT plugin (21.1.0) and Android SDK (21.1.0) and tested in a real Android device (Android 2.3.6  -  GingerBread).


1. Create a new Android application project namely “LocationMarkerSQLite”

Create an Android application project

Figure 1 : Create an Android application project


2. Configure the project

Configure the application project

Figure 2 : Configure the application project


3. Design application launcher icon

Design application launcher icon

Figure 3 : Design application launcher icon


4. Create a blank activity

Create a blank activity

Figure 4 : Create a blank activity


5. Enter MainActivity details

Enter MainActivity Details

Figure 5 : Enter MainActivity Details


6. Download and configure Google Play Services Library in Eclipse

Google Map for Android is now integrated with Google Play Services. So we need to set up Google Play Service Library for developing Google Map application in Android.

Please follow the given below link to setup Google Play Service library in Eclipse.

http://developer.android.com/google/play-services/setup.html


7. Add Google Play Services Library to this project

Link Google Play Services Library to this project

Figure 6 : Link Google Play Services Library to this project


8. Get the API key for Google Maps Android API V2

We need to get an API key from Google to use Google Maps in Android application.

Please follow the given below link to get the API key for Google Maps Android API v2.

https://developers.google.com/maps/documentation/android/start


9. Add Android Support library to this project

By default, Android support library (android-support-v4.jar ) is added to this project by Eclipse IDE to the directory libs. If it is not added, we can do it manually by doing the following steps :

  • Open Project Explorer by Clicking “Window -> Show View -> Project Explorer”
  • Right click this project
  • Then from popup menu, Click “Android Tools -> Add Support Library “

10. Update the layout file res/layout/activity_main.xml


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >

    <fragment
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</RelativeLayout>


11. Create a table class in the file src/in/wptrafficanalyzer/locationmarkersqlite/LocationsDB.java


package in.wptrafficanalyzer.locationmarkersqlite;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class LocationsDB extends SQLiteOpenHelper{

    /** Database name */
    private static String DBNAME = "locationmarkersqlite";

    /** Version number of the database */
    private static int VERSION = 1;

    /** Field 1 of the table locations, which is the primary key */
    public static final String FIELD_ROW_ID = "_id";

    /** Field 2 of the table locations, stores the latitude */
    public static final String FIELD_LAT = "lat";

    /** Field 3 of the table locations, stores the longitude*/
    public static final String FIELD_LNG = "lng";

    /** Field 4 of the table locations, stores the zoom level of map*/
    public static final String FIELD_ZOOM = "zom";

    /** A constant, stores the the table name */
    private static final String DATABASE_TABLE = "locations";

    /** An instance variable for SQLiteDatabase */
    private SQLiteDatabase mDB;

    /** Constructor */
    public LocationsDB(Context context) {
        super(context, DBNAME, null, VERSION);
        this.mDB = getWritableDatabase();
    }

    /** This is a callback method, invoked when the method getReadableDatabase() / getWritableDatabase() is called
    * provided the database does not exists
    * */
    @Override
    public void onCreate(SQLiteDatabase db) {
        String sql =     "create table " + DATABASE_TABLE + " ( " +
                         FIELD_ROW_ID + " integer primary key autoincrement , " +
                         FIELD_LNG + " double , " +
                         FIELD_LAT + " double , " +
                         FIELD_ZOOM + " text " +
                         " ) ";

        db.execSQL(sql);
    }

    /** Inserts a new location to the table locations */
    public long insert(ContentValues contentValues){
        long rowID = mDB.insert(DATABASE_TABLE, null, contentValues);
        return rowID;
    }

    /** Deletes all locations from the table */
    public int del(){
        int cnt = mDB.delete(DATABASE_TABLE, null , null);
        return cnt;
    }

    /** Returns all the locations from the table */
    public Cursor getAllLocations(){
        return mDB.query(DATABASE_TABLE, new String[] { FIELD_ROW_ID,  FIELD_LAT , FIELD_LNG, FIELD_ZOOM } , null, null, null, null, null);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    }

}


12. Create content provider class  in the file src/in/wptrafficanalyzer/locationmarkersqlite/LocationsContentProvider.java


package in.wptrafficanalyzer.locationmarkersqlite;

import java.sql.SQLException;

import android.content.ContentProvider;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.UriMatcher;
import android.database.Cursor;
import android.net.Uri;

/** A custom Content Provider to do the database operations */
public class LocationsContentProvider extends ContentProvider{

    public static final String PROVIDER_NAME = "in.wptrafficanalyzer.locationmarkersqlite.locations";

    /** A uri to do operations on locations table. A content provider is identified by its uri */
    public static final Uri CONTENT_URI = Uri.parse("content://" + PROVIDER_NAME + "/locations" );

    /** Constant to identify the requested operation */
    private static final int LOCATIONS = 1;

    private static final UriMatcher uriMatcher ;

    static {
        uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
        uriMatcher.addURI(PROVIDER_NAME, "locations", LOCATIONS);
    }

    /** This content provider does the database operations by this object */
    LocationsDB mLocationsDB;

    /** A callback method which is invoked when the content provider is starting up */
    @Override
    public boolean onCreate() {
        mLocationsDB = new LocationsDB(getContext());
        return true;
    }

    /** A callback method which is invoked when insert operation is requested on this content provider */
    @Override
    public Uri insert(Uri uri, ContentValues values) {
        long rowID = mLocationsDB.insert(values);
        Uri _uri=null;
        if(rowID>0){
            _uri = ContentUris.withAppendedId(CONTENT_URI, rowID);
        }else {
            try {
                throw new SQLException("Failed to insert : " + uri);
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        return _uri;
    }

    @Override
    public int update(Uri uri, ContentValues values, String selection,
        String[] selectionArgs) {
        // TODO Auto-generated method stub
        return 0;
    }

    /** A callback method which is invoked when delete operation is requested on this content provider */
    @Override
    public int delete(Uri uri, String selection, String[] selectionArgs) {
        int cnt = 0;
        cnt = mLocationsDB.del();
        return cnt;
    }

    /** A callback method which is invoked by default content uri */
    @Override
    public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {

        if(uriMatcher.match(uri)==LOCATIONS){
            return mLocationsDB.getAllLocations();
        }
        return null;
    }

    @Override
    public String getType(Uri uri) {
        return null;
    }
}


13. Update the class “MainActivity” in the file src/in/wptrafficanalyzer/locationmarkersqlite/MainActivity.java


package in.wptrafficanalyzer.locationmarkersqlite;

import android.app.Dialog;
import android.content.ContentValues;
import android.database.Cursor;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.LoaderManager.LoaderCallbacks;
import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader;
import android.view.Menu;
import android.widget.Toast;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.GoogleMap.OnMapClickListener;
import com.google.android.gms.maps.GoogleMap.OnMapLongClickListener;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

public class MainActivity extends FragmentActivity implements LoaderCallbacks<Cursor> {

    GoogleMap googleMap;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // Getting Google Play availability status
        int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getBaseContext());

        // Showing status
        if(status!=ConnectionResult.SUCCESS){ // Google Play Services are not available

            int requestCode = 10;
            Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, this, requestCode);
            dialog.show();

        }else { // Google Play Services are available

            // Getting reference to the SupportMapFragment of activity_main.xml
            SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);

            // Getting GoogleMap object from the fragment
            googleMap = fm.getMap();

            // Enabling MyLocation Layer of Google Map
            googleMap.setMyLocationEnabled(true);

            // Invoke LoaderCallbacks to retrieve and draw already saved locations in map
            getSupportLoaderManager().initLoader(0, null, this);
        }

        googleMap.setOnMapClickListener(new OnMapClickListener() {

            @Override
            public void onMapClick(LatLng point) {

                // Drawing marker on the map
                drawMarker(point);

                // Creating an instance of ContentValues
                ContentValues contentValues = new ContentValues();

                // Setting latitude in ContentValues
                contentValues.put(LocationsDB.FIELD_LAT, point.latitude );

                // Setting longitude in ContentValues
                contentValues.put(LocationsDB.FIELD_LNG, point.longitude);

                // Setting zoom in ContentValues
                contentValues.put(LocationsDB.FIELD_ZOOM, googleMap.getCameraPosition().zoom);

                // Creating an instance of LocationInsertTask
                LocationInsertTask insertTask = new LocationInsertTask();

                // Storing the latitude, longitude and zoom level to SQLite database
                insertTask.execute(contentValues);

                Toast.makeText(getBaseContext(), "Marker is added to the Map", Toast.LENGTH_SHORT).show();
            }
        });

        googleMap.setOnMapLongClickListener(new OnMapLongClickListener() {
            @Override
            public void onMapLongClick(LatLng point) {

                // Removing all markers from the Google Map
                googleMap.clear();

                // Creating an instance of LocationDeleteTask
                LocationDeleteTask deleteTask = new LocationDeleteTask();

                // Deleting all the rows from SQLite database table
                deleteTask.execute();

                Toast.makeText(getBaseContext(), "All markers are removed", Toast.LENGTH_LONG).show();
            }
        });
    }

    private void drawMarker(LatLng point){
        // Creating an instance of MarkerOptions
        MarkerOptions markerOptions = new MarkerOptions();

        // Setting latitude and longitude for the marker
        markerOptions.position(point);

        // Adding marker on the Google Map
        googleMap.addMarker(markerOptions);
    }

    private class LocationInsertTask extends AsyncTask<ContentValues, Void, Void>{
        @Override
        protected Void doInBackground(ContentValues... contentValues) {

            /** Setting up values to insert the clicked location into SQLite database */
            getContentResolver().insert(LocationsContentProvider.CONTENT_URI, contentValues[0]);
            return null;
        }
    }

    private class LocationDeleteTask extends AsyncTask<Void, Void, Void>{
        @Override
        protected Void doInBackground(Void... params) {

            /** Deleting all the locations stored in SQLite database */
            getContentResolver().delete(LocationsContentProvider.CONTENT_URI, null, null);
            return null;
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public Loader<Cursor> onCreateLoader(int arg0,
        Bundle arg1) {

        // Uri to the content provider LocationsContentProvider
        Uri uri = LocationsContentProvider.CONTENT_URI;

        // Fetches all the rows from locations table
        return new CursorLoader(this, uri, null, null, null, null);
    }

    @Override
    public void onLoadFinished(Loader<Cursor> arg0,
        Cursor arg1) {
        int locationCount = 0;
        double lat=0;
        double lng=0;
        float zoom=0;

        // Number of locations available in the SQLite database table
        locationCount = arg1.getCount();

        // Move the current record pointer to the first row of the table
        arg1.moveToFirst();

        for(int i=0;i<locationCount;i++){

            // Get the latitude
            lat = arg1.getDouble(arg1.getColumnIndex(LocationsDB.FIELD_LAT));

            // Get the longitude
            lng = arg1.getDouble(arg1.getColumnIndex(LocationsDB.FIELD_LNG));

            // Get the zoom level
            zoom = arg1.getFloat(arg1.getColumnIndex(LocationsDB.FIELD_ZOOM));

            // Creating an instance of LatLng to plot the location in Google Maps
            LatLng location = new LatLng(lat, lng);

            // Drawing the marker in the Google Maps
            drawMarker(location);

            // Traverse the pointer to the next row
            arg1.moveToNext();
        }

        if(locationCount>0){
            // Moving CameraPosition to last clicked position
            googleMap.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(lat,lng)));

            // Setting the zoom level in the map on last position  is clicked
            googleMap.animateCamera(CameraUpdateFactory.zoomTo(zoom));
        }
    }

    @Override
    public void onLoaderReset(Loader<Cursor> arg0) {
        // TODO Auto-generated method stub
    }
}


14. Update the file AndroidManifest.xml


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="in.wptrafficanalyzer.locationmarkersqlite"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

    <permission
        android:name="in.wptrafficanalyzer.locationmarkersqlite.permission.MAPS_RECEIVE"
        android:protectionLevel="signature"/>

    <uses-permission android:name="in.wptrafficanalyzer.locationmarkersqlite.permission.MAPS_RECEIVE"/>

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true"/>

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="in.wptrafficanalyzer.locationmarkersqlite.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <provider
            android:name="LocationsContentProvider"
            android:authorities="in.wptrafficanalyzer.locationmarkersqlite.locations"
            android:exported="false" />

        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="YOUR_ANDROID_API_KEY" />
    </application>
</manifest>

Note : Replace “YOUR_ANDROID_API_KEY” with the Android API key obtained in Step 8.


15. Executing the application

In Eclipse IDE, we can execute the application from the menu “Run -> Runs As -> Android Application

Screenshot of the application in execution

Figure 7 : Screenshot of the application in execution


16. Download the source code


How to hire me?

I am George Mathew, working as software architect and Android app developer at wptrafficanalyzer.in

You can hire me on hourly basis or on project basis for Android applications development.

For hiring me, please mail your requirements to info@wptrafficanalyzer.in.

My other blogs
store4js.blogspot.com


Android Knowledge Quiz

Ready to test your knowledge in Android? Take this quiz :



Tags: , , , , , , , , , , ,

49 Responses to Storing and retrieving locations in SQLite from Google Maps Android API V2

  1. mithran on April 24, 2013 at 10:32 am

    I have downloaded this code and did everything that mentioned above.but while launched the app.it stopped unfortunately………..help!!!

    • george on April 24, 2013 at 10:39 am

      Are you getting any hint in Logcat regarding the error occurred while launching the app?

      • mithran on April 24, 2013 at 11:06 am

        04-24 11:05:29.523: E/AndroidRuntime(774): FATAL EXCEPTION: main
        04-24 11:05:29.523: E/AndroidRuntime(774): java.lang.RuntimeException: Unable to start activity ComponentInfo{in.wptrafficanalyzer.locationmarkersqlite/in.wptrafficanalyzer.locationmarkersqlite.MainActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
        04-24 11:05:29.523: E/AndroidRuntime(774): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
        04-24 11:05:29.523: E/AndroidRuntime(774): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
        04-24 11:05:29.523: E/AndroidRuntime(774): at android.app.ActivityThread.access$600(ActivityThread.java:130)
        04-24 11:05:29.523: E/AndroidRuntime(774): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
        04-24 11:05:29.523: E/AndroidRuntime(774): at android.os.Handler.dispatchMessage(Handler.java:99)
        04-24 11:05:29.523: E/AndroidRuntime(774): at android.os.Looper.loop(Looper.java:137)
        04-24 11:05:29.523: E/AndroidRuntime(774): at android.app.ActivityThread.main(ActivityThread.java:4745)
        04-24 11:05:29.523: E/AndroidRuntime(774): at java.lang.reflect.Method.invokeNative(Native Method)
        04-24 11:05:29.523: E/AndroidRuntime(774): at java.lang.reflect.Method.invoke(Method.java:511)
        04-24 11:05:29.523: E/AndroidRuntime(774): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
        04-24 11:05:29.523: E/AndroidRuntime(774): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
        04-24 11:05:29.523: E/AndroidRuntime(774): at dalvik.system.NativeStart.main(Native Method)
        04-24 11:05:29.523: E/AndroidRuntime(774): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment

        • george on April 24, 2013 at 3:27 pm

          Please try the following :

          => Uninstall this application from your Android device

          => Clean this project ( In Eclipse IDE, use the menu Project -> Clean … )

          => Run the application ( In Eclipse IDE, use the menu Run -> Run As -> Android Application )

          • js on May 9, 2013 at 1:32 am

            I follow your instruction already…but still same the error…
            Can I ask how to track user location and draw the route path when user move.
            Thank you very much first

        • David on June 11, 2013 at 11:34 pm

          I had the same issue and had to add SupportMapFragment to the XML

          • akhwan on August 17, 2013 at 8:33 pm

            it is worked?? please tell me how to add SupportMapFragment to the XML

        • vineet on January 16, 2014 at 12:36 pm

          i’m also having the same errors.plz tell me how can i remove it.

  2. chris on April 29, 2013 at 4:18 pm

    hello

    very good!!

    thank for your work
    christophe

  3. Marilia on May 5, 2013 at 3:17 am

    Hello, well the initLoader has an error for me,
    The method initLoader(int, Bundle, LoaderManager.LoaderCallbacks) in the type LoaderManager is not applicable for the arguments (int, null, MapsActivity).

    How can I solve this!? pleasee

    • george on May 6, 2013 at 6:47 am

      Hello Marilia,
      Please ensure that, the class MainActivity is importing “android.support.v4.app.LoaderManager.LoaderCallbacks”.

  4. Marilia on May 10, 2013 at 2:37 am

    Ok now I run it but the problem seem to be on the database, and the problem is in the getAllLocations() funtion.

    05-07 18:39:10.099: E/AndroidRuntime(15828): Caused by: java.lang.NullPointerException
    05-07 18:39:10.099: E/AndroidRuntime(15828): at com.appproyecto.DBAdapter.getAllLocations(DBAdapter.java:219)
    05-07 18:39:10.099: E/AndroidRuntime(15828): at com.appproyecto.LocationContentProvider.query(LocationContentProvider.java:81)
    05-07 18:39:10.099: E/AndroidRuntime(15828): at android.content.ContentProvider$Transport.query(ContentProvider.java:187)
    05-07 18:39:10.099: E/AndroidRuntime(15828): at android.content.ContentResolver.query(ContentResolver.java:262)
    05-07 18:39:10.099: E/AndroidRuntime(15828): at android.support.v4.content.CursorLoader.loadInBackground(CursorLoader.java:49)
    05-07 18:39:10.099: E/AndroidRuntime(15828): at android.support.v4.content.CursorLoader.loadInBackground(CursorLoader.java:35)
    05-07 18:39:10.099: E/AndroidRuntime(15828): at android.support.v4.content.AsyncTaskLoader.onLoadInBackground(AsyncTaskLoader.java:240)
    05-07 18:39:10.099: E/AndroidRuntime(15828): at android.support.v4.content.AsyncTaskLoader$LoadTask.doInBackground(AsyncTaskLoader.java:51)
    05-07 18:39:10.099: E/AndroidRuntime(15828): at android.support.v4.content.AsyncTaskLoader$LoadTask.doInBackground(AsyncTaskLoader.java:40)
    05-07 18:39:10.099: E/AndroidRuntime(15828): at android.support.v4.content.ModernAsyncTask$2.call(ModernAsyncTask.java:123)
    05-07 18:39:10.099: E/AndroidRuntime(15828): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
    05-07 18:39:10.099: E/AndroidRuntime(15828): … 4 more

  5. chris on May 22, 2013 at 12:52 am

    hello
    i do it but i have a probleme
    the number of marker read isn’t the same when i read the sqlitedata

    when i reload the activity
    (1900 marker stored checked ok well stored)
    when i do the activity sometime 530 marker showed
    sometime 280, sometime 1900

    why???

    thank for your help
    Christophe

  6. chris on May 31, 2013 at 1:21 am

    hello i dont know how to do, can you help me
    i store in data bvase the good number of data
    but when i read it, it does’n read the same number of data??

    thanks
    chris

  7. Tayyaba Jan on June 22, 2013 at 11:30 pm

    hi… nice tutorials. i need your help in my project. i am using sqlite database and want to retrieve values on the map in form of overlay. you used here content provider etc my sqlite database is designed with ADAPTER class. please help me..
    thanx

  8. Ricky on July 20, 2013 at 2:48 am

    Thanks for the sharing. But, now, I am facing a problem. I have several thousand rows in the sqlite. When I load the data at once and I touched the screen, it will show “the app is not responding” either “wait” or “close”. Do you know what problem cause this issue?

    • george on July 20, 2013 at 7:01 am

      Are you sure, you are retrieving the data in a non-ui thread.

      • Ricky on July 20, 2013 at 5:42 pm

        I run AsyncTask in onLoadFinished. loop through the data in doInBackground and store them into ArrayList. Finally, pass ArrayList to onPostExecute and loop through the ArrayList to addMarker on maps. Am I do right?

  9. deepak mamdapure on August 7, 2013 at 5:16 pm

    your tutorial is very very good..i like it….i have one question i added name column with this database and i am getting that name in spinner…what i want to do when i click on spinner item that time i want to redraw location for that perticular saved name from sqlite to map……plz suggest me how i do this……..

    • george on August 7, 2013 at 5:35 pm

      1. Get the selected item name in itemclick listener of the spinner.
      2. With this name, you can fetch corresponding latitude , longitude pair from the sqlite database using ContentProvider in asynchronous mode.
      3. Draw the coordinate in the map.

      • deepak mamdapure on August 7, 2013 at 5:50 pm

        but i am not getting can i send u source code so please correct them….i know i am doing some silly mistakes but please help me

  10. aviv on August 14, 2013 at 6:33 pm

    hi there
    thanks for all of this… its amazing

    i am kind of new to all of this stuff….
    what steps should i take to be able to launch this app? i dont have sqlite on my computer. after i download it – what should i do? how do i make this app talk with it?

    • George Mathew on August 14, 2013 at 7:01 pm

      * After downloading, extract the zip file
      * Import the extracted folder into your eclipse, which is already configured for Android app development
      * Run the application as Android Application
      * Then the application will be executed in the Android device connected to your machine

      Note : You don’t need any sqlite database in your computer. Sqlite database will be already there in the Android.

  11. akhwan on August 16, 2013 at 8:19 pm

    sorry i don’t understand metode above

    i want to save 15 markers on the database SQLite and they can just added by me (only admin, the user can’t add marker), please tell me how to do it.

    thanks before.

  12. DJ on December 29, 2013 at 12:14 pm

    Why are you using the provider tag “” in the Manifest.

  13. Josue on January 3, 2014 at 7:06 pm

    I wonder have you as you give me an explanation or example showing how to insert my lat and log stored in slqite and show map v2.
    already analyzed your sample: Storing and retrieving locations in SQLite Android from Google Maps API V2, but it does not give me much light.
    I already have stored and returned my coordinates, so would like to know how exibilas map. very Obrigado.Josue

  14. sathish kumar on January 16, 2014 at 3:04 pm

    hai am follow same procedure but when am run the application it will show the error as unfortunately application was stopped… pls help me……. thanks in advance….

  15. Marco Giadone on April 23, 2014 at 3:55 pm

    hi first of all I would like to congratulate you for the excellent guide. I created an application that manages to do all memorized all ‘inside of a sqlite database and I would now enter multiple alert for each marker in the map .. how should I proceed?

  16. Waqas on September 7, 2014 at 1:38 pm

    Great tutorial…!
    Now, i want to store the marker in ListActivity. How can i do?
    Thanks in advance.

  17. Snoww on September 26, 2014 at 9:21 pm

    Tks for this useful topic.
    I’m new beginer with android google map api so all your guide is very useful for me.
    I try to run your project. Everything work fine. But can i ask a noob question? This is where the database located when i add some location on googlemap? Can i view and edit that database with sqlite studio?

  18. Rajatha B.M on November 10, 2014 at 3:06 pm

    Thank you so much for the tutorial but when we tried to execute the above code and run it on the emulator, says “unfortunately stopped working” .
    Tried uninstalling and cleaning the project but that did not help either.
    Any help will be appreciated.
    Thank you.

  19. Rene Torres on January 14, 2015 at 10:51 am

    very good (y), muy bueno
    saludos desde mexico

  20. Segunio on February 19, 2015 at 1:34 pm

    I tried and got the same message mentioned above and series of efforts made to rectify the problem turned abortive.

    In the end I managed to get it work by deleting my emulators and creating a new one.

    I tried to run in again and it worked.

  21. Naimuddin on March 20, 2015 at 6:33 pm

    Sir, i’m having a code where i can get gps coordinates and send it to server using gprs. But if gprs is not there then it wont send my location to server. So please provide me a code where i can save my gps coordinates in my database, when GPRS is not there, and when GPRS is active then i should retrive those coordinates that are saved in my database, and my current location, and send it to the server. Please help me out in this. Thank you

  22. malek on April 2, 2015 at 3:49 am

    ur project is verry nice i try to implement it in a project that show nearby places in map
    i have not errors but when i clik nothing changes i think cause the map is alredy marked plz help me

  23. cv on April 21, 2015 at 1:27 am

    How to delete one marker from SQLite database on click info windows and delete onItemClickListener?

  24. cv on April 21, 2015 at 8:19 pm

    How to delete only one marker in SQLite using click info windows and onItemClickListener?

  25. walid on April 28, 2015 at 4:36 am

    first of all thanks for sharing this for us,i want to ask you ,i make this project as a second activity ,when i click on button from the first activity to go to second act,it shows me an error in setOnMapLongClickListener

  26. Devank on December 26, 2015 at 6:18 pm

    sir,
    the error is shown as
    Initializing project state error
    and as soon as i click the intent button it navigates back out of the app. please sort out the problem.

  27. Devank on December 26, 2015 at 6:20 pm

    sorted out the error by fix project setup

  28. aneesirshad on February 5, 2016 at 3:57 pm

    how i get coordinates from server i use android studio. and show all all projects by pushpin

  29. ankita on February 11, 2016 at 5:14 pm

    What i can do for this…
    i tried everything but issue not resolving….
    Binary XML file line #7: Error inflating class fragment
    android.view.InflateException: Binary XML file line #7: Error inflating class fragment

    java.lang.NullPointerException: name == null

  30. ankita on February 12, 2016 at 3:34 pm

    Sir,
    I have done with some errors…
    now m facing problem,after app run it will get crash…because of null pointer exception LoadFinished…
    please help me…

  31. manisha on March 17, 2016 at 4:02 pm

    Im trying your application from 2 days..I get stopped..I did all the step u instructed. please help me..Its my final year project part.I have to submit in 1 week

  32. thrishool on March 22, 2016 at 7:39 pm

    please can u giv the code for android studio… android studio has some gradle build process and i am getting errors if i try on it.. please paste the version of code for android studio.. as i am in need of it.. thank u

  33. Avinash Chalise on May 25, 2016 at 7:17 pm

    please post the video tutorial for the project in android studio

  34. Danushka on May 28, 2016 at 6:58 pm

    Good job buddy… And Really nice

  35. sachin on June 14, 2016 at 12:58 pm

    sir,
    do i have to change this string in my app.??
    line:15:public static final String PROVIDER_NAME = “in.wptrafficanalyzer.locationmarkersqlite.locations”;

    “in.wptrafficanalyzer.locationmarkersqlite”,its ur package name na?
    so if i give mypackage.location it is showing error.

Leave a Reply

Your email address will not be published. Required fields are marked *

Be friend at g+

Subscribe for Lastest Updates

FBFPowered by ®Google Feedburner