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 7162055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:40:17+00:00 2026-05-28T13:40:17+00:00

My application have to load some points from internal sqlite database of android, and

  • 0

My application have to load some “points” from internal sqlite database of android, and it converts this points into lines on a map, then, from the database, I load other “points” which becomes markers on the map.

The problem is that the loading process described above is awfully slow. This process can take many seconds, and also minutes in the worst case.

The points in database come from a service, which trace your position. I have implemented in this service some methods to avoid a surplus of points, like time control (if two subsequent points have been taken too near in time, the second is not saved), position control (if two subsequent points have the same coordinates, the last will not be saved) and distance check (if two subsequent points are too near in distance, the last will not be saved).

Other computations can occour on these points during the loading, but slowness is present also in the best case, where it’s only the reading from database.

This is where I create the array which contains points for draw lines on map.

public BuildPointsList(Context context, long travelId) {
    this.context=context;
    this.travelId = travelId;
    initializePointList();
}
   private void initializePointList() {
    pointsList = new ArrayList<Points>();
}

public List<Points> fromDB() {
    TravelDB traveldb = new TravelDB(context);
    traveldb.open();
    Cursor cursor = traveldb.fetchAllGpsPoints(travelId);

    loadPoints(cursor);
    cursor.close();
    traveldb.close();
    return pointsList;
}

protected void loadPoints(Cursor cursor) {

    initializePointList();
    cursor.moveToFirst();
    int gpsIndex = cursor.getColumnIndex(colGpsId);
    int latitudeIndex = cursor.getColumnIndex(colGpsLatitude);
    int longitudeIndex = cursor.getColumnIndex(colGpsLongitude);
    int dateIndex = cursor.getColumnIndex(colGpsDate);

    for (int progress=0; progress<cursor.getCount(); progress++) {
        Points points = new Points();
        points.setLatitude(cursor.getInt(latitudeIndex));
        points.setLongitude(cursor.getInt(longitudeIndex));
        points.setDataRilevamento(cursor.getLong(dateIndex));
        points.setGpsId(cursor.getInt(gpsIndex));

        pointsList.add(points);

        cursor.moveToNext();
    } 
}

Here is where I build the array which contains points for markers, for every marker exist one or more images

private void buildPoints () {

    List<Images> images = travel.getImages();
    Log.i("DDV", "images:"+images.size());
    // se esistono punti
    if (!images.isEmpty()) {

        length = images.size();

        for (progress = 0 ; progress < length; progress++) {

            currentImage = images.get(progress);

            // verifico se una località con coordinate simili era già stata presa in esame
            // in quel caso la raggruppo insieme alle altre
            if ((oldImage != null) && (near(oldImage.getGeopoint(), currentImage.getGeopoint()))) {

                overlayitem.addImage(currentImage);
                if (currentImage.getAddress().length() == 0) {
                    if (oldImage.getAddress().length() > 0) {
                        currentImage.setAddress(oldImage.getAddress());
                        travel.addImages(currentImage);
                    }
                }
            }

            // in questo caso vuol dire che le coordinate sono troppo differenti per unirle in una
            // quindi salvo l'oggetto vecchio e ne instanzio uno nuovo
            else if (oldImage != null) {
                    setTextAndSave(oldImage);
                    createOverlay(currentImage.getGeopoint());
                    oldImage = currentImage;
                }

            // in questo caso è la prima volta che instanzio una coordinata
            else {

                oldImage = currentImage;

                // geocoding per determinare il nome della via dove è stato generato il contenuto
                // se nel db non è presente

                if (currentImage.getAddress().length() == 0) 
                    currentImage = geoCode(currentImage);                       

                // aggiungo il marker
                createOverlay(currentImage.getGeopoint());
            }                   

            // faccio progredire la sbarra
            onProgressUpdate((int)(progress*100/length));
        }
        setTextAndSave(oldImage);
    }
}   

This is where I build the line for the map

private void buildRoute() {

    points = travel.getPoints();    

    length = points.size();
    long tmp = DateManipulation.getCurrentTimeMs();
    Log.i("DDV", "START PARSIN POINTSL: " +tmp);

    if (length > 1) {

        Points currentPoint = points.get(0);
        Points oldPoint=currentPoint;

        for (int progress=0; progress<length; progress++) {

            currentPoint = points.get(progress);

            if (currentPoint.getGeoPoint() != oldPoint.getGeoPoint()) {
                oldPoint = currentPoint;
                polyLine.add(currentPoint.getGeoPoint());
                setZoomAndCenter(currentPoint);

            }
            onProgressUpdate((int)(progress*100/length));
        }
    }
    saveCenterPosition();
}

If do you need something else, ask freely.

Thank you to all.

EDIT – Here is the method getGeoPoint

public GeoPoint getGeoPoint() {
    GeoPoint geoPoint = new GeoPoint(latitude, longitude);
    return geoPoint;
}
  • 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-28T13:40:18+00:00Added an answer on May 28, 2026 at 1:40 pm

    I would recommend you do some tracing with DDMS, it’ll show you where you’re spending your most time and help you optimize.

    I suspect, after dealing with GeoPoint, that you’re not doing enough caching. The “new GeoPoint” constructor is extremely expensive so if you’re doing a few hundred operations of that instantiation, I recommend re-thinking how you cache that.

    I’d like to see the logic behind codePoint.getGeoPoint()

    I see that you’re storing the raw lat/lng in the database. That will be fast to go in and out. Again, I assume it’s the creation of your GeoPoint object that’s taking a lot of time. Sadly, there’s no way to make GeoPoint serializable and store that. So you’re stuck instantiating it as soon as you pull it out of the database.

    Do a trace, let’s see what the result of that is. 🙂

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

Sidebar

Related Questions

I have an application which tries to load some expected registry settings within its
I have a console application that is trying to load a CustomConfigurationSection from a
I have an application that extracts data from some xml that is stored in
In a Java web application I have a recurring message load of type A
I have an application the will load usercontrols dynamically depending on the user. You
We have an application that runs over load balanced server instances, and therefore is
I have an application with one form in it, and on the Load method
I have a Java Application which has to load an DLL with a few
I have a web application that can load plugins through reflection. It currently uses
I have an environment where 2 load-balanced clustered tomcats pointing to same application. When

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.