Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7622371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:26:06+00:00 2026-05-31T04:26:06+00:00

i am trying to create a Map Activity and i have been able to

  • 0

i am trying to create a Map Activity and i have been able to successfully have a static string of coordinates to be read from the main activity, however this is hard coded and i wish you insert these coordinates into an SQLite Database and for them to be read.
I have tried looking around but i simply cant get the answer that i am looking for, and i would grateful if someone could help me out please

Heres my Main Activity – GMapsActivity.java:

    /** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) 
{   
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    mapView = (MapView)findViewById(R.id.map_view);
    mapView.setBuiltInZoomControls(true);
    //mapView.setStreetView(true);
    mapController = mapView.getController();

    String coordinates[] = {"51.52241608253253","-0.1318359375"};
    double lat = Double.parseDouble(coordinates[0]);
    double lng = Double.parseDouble(coordinates[1]);
    GeoPoint general = new GeoPoint((int) (lat * 1E6), (int) (lng * 1E6) );
    mapController.setZoom(10);
    mapController.animateTo(general);

    mapOverlays = mapView.getOverlays();
    drawable = this.getResources().getDrawable(R.drawable.blue);
    itemizedOverlay = new NewItemizedOverlay(drawable, this);

    GeoPoint point = new GeoPoint((int)(51.555890943494276*1E6), (int)(-0.39989858865737915*1E6));
    OverlayItem overlayitem = new OverlayItem(point, "Greenword Veterinary" , "57 Station Approach, South Ruislip, Ruislip, Middlesex, HA4 6SL, 020 8845 8144");
    itemizedOverlay.addOverlay(overlayitem);

    GeoPoint point2 = new GeoPoint((int)(51.598707*1E6), (int)(-0.393416*1E6));
    OverlayItem overlayitem2 = new OverlayItem(point2, "MediVet Pinner" , "2A Pinner Green, Pinner, Middlesex, HA5 2AA, 020 8866 0727");
    itemizedOverlay.addOverlay(overlayitem2);

    GeoPoint point3 = new GeoPoint((int)(51.670865*1E6), (int)(-0.397034*1E6));
    OverlayItem overlayitem3 = new OverlayItem(point3, "MediVet Watford" , "237 Saint Albans Road, Watford, Hertfordshire WD24 5BP, 01923 243 429");
    itemizedOverlay.addOverlay(overlayitem3);
    mapOverlays.add(itemizedOverlay);

    myLocationOverlay = new MyLocationOverlay(this, mapView);
    mapView.getOverlays().add(myLocationOverlay);

And this is my database creator – DatabaseManager.java

package com.javacodegeeks.android.googlemaps;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;

public class DatabaseManager {

public static final String KEY_ID = "_id";
public static final String KEY_LAT = "vetlat";
public static final String KEY_LONGI = "vetlongi";
public static final String KEY_NAME = "vetname";
public static final String KEY_INFO = "vetinfo";

private static final String DATABASE_NAME = "myvet.db";
private static final String DATABASE_TABLE = "vetLocations";
private static final int DATABASE_VERSION = 1;

private DbHelper ourHelper;
private final Context ourContext;
private SQLiteDatabase ourDB;

private static class DbHelper extends SQLiteOpenHelper
{

    public DbHelper(Context context) 
    {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
        // TODO Auto-generated constructor stub
    }

    @Override
    public void onCreate(SQLiteDatabase db) 
    {
        // TODO Auto-generated method stub
        db.execSQL("CREATE TABLE " + DATABASE_TABLE + " (" + 
                KEY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + 
                KEY_LAT + "REAL NOT NULL," + 
                KEY_LONGI + "REAL NOT NULL," +
                KEY_NAME + "TEXT NOT NULL," +
                KEY_INFO + "TEXT NOT NULL);"
        );
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // TODO Auto-generated method stub
        db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE);
        onCreate(db);
    }

}

public DatabaseManager(Context c)
{
    ourContext = c;
}

public DatabaseManager open()
{
    ourHelper = new DbHelper(ourContext);
    ourDB = ourHelper.getReadableDatabase();
    return this;
}

public void close()
{
    ourHelper.close();
}

}

I am new to Android Programming so i would be grateful is someone could actually show me snippets of code as opposed to general directions since i dont really understand them lol

EDIT:
I have created database entries in an SQLite browser
How would i be able to make the main activity file read the values from that file?

A general idea that the code would try and call the values such as:
SELECT * FROM the DB
Put into Array
then loop it

points = ((int)([lat_value_from_db1*E6]), ((int)([longi_value_from_db1*E6]);
overlay = (points, [name_value_from_db], [info_value_from_db]);
itemizedOverylay.addOverlay(allOverlays);

Its just im really not sure how to implement this :/

I would really appreciate any form of help

Thank You in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T04:26:07+00:00Added an answer on May 31, 2026 at 4:26 am

    First, create a class as an object of database record DatabaseObject.java:

    public class DatabaseObject {
    
           int _id;
           double _lat;
           double _lng;
           String _name;
           String _info;
    
            // Empty constructor
            public DatabaseObject(){
    
            }
            // constructor
            public DatabaseObject(int id, double lat, double lng,String name ,String info){
                this._id = id;
                this._lat=lat;
                this._lng=lng;
                this._name=name;
                this._info=info;
            }
            public DatabaseObject(double lat, double lng,String name ,String info){
                 this._lat=lat;
                    this._lng=lng;
                    this._name=name;
                    this._info=info;
            }
            // constructor
    
            // getting ID
            public int getID(){
                return this._id;
            }
    
            // setting id
            public void setID(int id){
                this._id = id;
            }
    
    
            public double getlat(){
                return this._lat;
            }
    
            public void setlat(double lat){
                this._lat = lat;
            }
    
            public double getlng(){
                return this._lng;
            }
    
            public void setlng(double lng){
                this._lng = lng;
            }
    
            public String getname(){
                return this._name;
            }
    
            // setting id
            public void setname(String name){
                this._name = name;
            }
    
            public String getinfo(){
                return this._info;
            }
    
            // setting id
            public void setinfo(String info){
                this._infor= info;
            }   
    }
    

    Then add these two functions in your DatabaseManager.java:

    // Getting one database object by id
    public DatabaseObject get_DatabaseObject(int id) {
           SQLiteDatabase db = this.getReadableDatabase();
    
            Cursor cursor = db.query(TABLE_NAME, new String[] { KEY_ID,
                    KEY_LAT, KEY_LONGI,KEY_NAME,KEY_INFO }, KEY_ID + "=?",
                    new String[] { String.valueOf(id) }, null, null,null,null);
            if (cursor != null)
                cursor.moveToFirst();
    
            DatabaseObject data = new DatabaseObject(Integer.parseInt(cursor.getString(0)),
                    Double.parseDouble(cursor.getString(1)), Double.parseDouble(cursor.getString(2)),cursor.getString(3), cursor.getString(4));
            // return database object
           return data;
       }
    
        // Getting All database objects
        public List<DatabaseObject> getAllDatabaseObject() {
            List<DatabaseObject> contactList = new ArrayList<DatabaseObject>();
           //  Select All Query
            String selectQuery = "SELECT  * FROM " + TABLE_NAME;
    
            SQLiteDatabase db = this.getWritableDatabase();
            Cursor cursor = db.rawQuery(selectQuery, null);
    
            // looping through all rows and adding to list
            if (cursor.moveToFirst()) {
               do {
                   DatabaseObject data = new DatabaseObject();
                   data.setID(Integer.parseInt(cursor.getString(0)));
                    data.setLAT( Double.parseDouble(cursor.getString(1)));
                    data.setLONGI( Double.parseDouble(cursor.getString(2)));
                    data.setNAME(cursor.getString(3));
                   data.setINFO(cursor.getString(4));
    
                  //   Adding contact to list
                   contactList.add(data);
                } while (cursor.moveToNext());
            }
    
            // return database object list
           return dataList;
        }
    

    And now use these in any activity like this:

    1- Declare this as global variable:

    DatabaseManager db = new DatabaseManager(this);
    

    2- Retrieve all objects:

    List<DatabaseObject> K = db.getAllDatabaseObject(); 
    

    3- Use it in loop this way:

    for (DatabaseObject cn : K) {
            point = new GeoPoint((int)(cn.getlat()*E6), (int)(cn.getlng()*E6));
            overlayitem = new OverlayItem(point, cn.getname(), cn.getinfo());
            itemizedOverlay.addOverlay(overlayitem);
            mapOverlays.add(itemizedOverlay);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a custom javascript class that inherits from google.maps.Map (V3 API).
I'm trying to create a recursive map in F#. type RecMap = Map<string, RecMap>
I have an executable (say notepad.exe). I am trying to create a function map
I am trying to create a map activity with an overlay image on the
i've been trying to create a map-related android app, but i realized that the
I've been trying to create what I would have imagined would be a rather
I am trying to create a map from an interleaved list and running into
I'm trying to create a map, where the key is an int , and
I'm trying to create a mutable Map with a default that creates a new
I am trying to create a wpf control that will display a map image

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.