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

  • Home
  • SEARCH
  • 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 4112888
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T22:15:11+00:00 2026-05-20T22:15:11+00:00

Hy! I’m trying for days now to create an application that receives GPS data

  • 0

Hy!
I’m trying for days now to create an application that receives GPS data and has to store it in a Sqlite database.I’ve created the database and I also have an GeoPoints Array list that I put in my geopoints.The GPS data is simulated with the help of a KML file.
Now,my problem is that even though I succeded to display the map that is updated with the new locations while I try to read from the Sqlite database and display on the screen the geopoints I get nothing-no text displayed on the screen.

Here is my code:

public class screen4 extends MapActivity 
{    
    private LocationManager lm;
    private LocationListener locationListener;
    private MyLocationOverlay myLocOverlay;

    private MapView mapView;
    private MapController mc;

List<GeoPoint> geoPointsArray = new ArrayList<GeoPoint>();
    int latitude;
    int longitude;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.screen4); 
        lm = (LocationManager) 
            getSystemService(Context.LOCATION_SERVICE);    

        locationListener = new MyLocationListener();

        lm.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0,locationListener);

        mapView = (MapView) findViewById(R.id.mapview1);
        mapView.setBuiltInZoomControls(true);
        mc = mapView.getController();
        initMyLocation();
       DBAdapter db=new DBAdapter(this);
       db.createDatabase();
       db.openDataBase();
      for (int i = 0; i < geoPointsArray.size()-1; i++)
       {
           GeoPoint loc=geoPointsArray.get(i);

          db.insertData(Integer.toString(loc.getLongitudeE6()),Integer.toString(loc.getLatitudeE6()),null,null,null);


       }
      Cursor c=db.getAllData();
     if(c.moveToFirst()) 
     {
      do{
          DisplayTitle(c);
      }while(c.moveToNext());

     }
     if(c!=null&&!c.isClosed()){
        db.close();
     }

    }

    private void initMyLocation() {
        myLocOverlay = new MyLocationOverlay(this, mapView);
        myLocOverlay.enableMyLocation();
        mapView.getOverlays().add(myLocOverlay);

    }
    public void DisplayTitle(Cursor c)
    {
        Toast.makeText(this, 
                "longitude: " + c.getString(0) + "\n" +
                "latitude: " + c.getString(1) + "\n",
                Toast.LENGTH_LONG).show();        
    } 
    private class MyLocationListener implements LocationListener 
    {
        @Override
        public void onLocationChanged(Location loc) {
            if (loc != null) {                         
                latitude=(int) (loc.getLatitude()* 1E6);
                longitude=(int) (loc.getLongitude()* 1E6);



           GeoPoint p = new GeoPoint(latitude,longitude);
           geoPointsArray.add(p);

                mc.animateTo(p);
              mc.setZoom(17);                
                mapView.invalidate();
                mapView.setSatellite(true);
           }

        }

        @Override
        public void onProviderDisabled(String provider) {
            // TODO Auto-generated method stub
        }

        @Override
        public void onProviderEnabled(String provider) { 

        }
        @Override
        public void onStatusChanged(String provider, int status, Bundle extras) { 

        }
    }

    protected boolean isRouteDisplayed() {
        // TODO Auto-generated method stub
        return false;
    } 

     }

I did debug to my code line by line and as I get to this line(the first one):

 for (int i = 0; i < geoPointsArray.size()-1; i++)
       {
           GeoPoint loc=geoPointsArray.get(i);
           db.insertData(Integer.toString(loc.getLongitudeE6()),Integer.toString(loc.getLatitudeE6()),null,null,null);
       }

the debugger jumps this snippet…now to me that means that I have no point in my geoPointsArray and I have nothing to store in the data base and there is nothing to read from Sqlite.
Can someone help me please with some ideas.Thank you

  • 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-20T22:15:12+00:00Added an answer on May 20, 2026 at 10:15 pm

    In general if guards for arrays should be i < size and not i < size - 1.

    To avoid mistakes in guards altogether you might use:

    for (GeoPoint loc : geoPointsArray) {
        ....
    

    instead.

    Edit – Also, your database access only seems to be performed in onCreate. You need to do this in your LocationListener if you expect it to be called when you get updates.

    onCreate is only called once when your activity is created. You should open your database here and then do your accesses when you actually get the data.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
I have just tried to save a simple *.rtf file with some websites and

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.