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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:00:48+00:00 2026-05-22T01:00:48+00:00

I’m using a background thread to read some data from my database.The data that

  • 0

I’m using a background thread to read some data from my database.The data that I read is GPS(latitude,lobgitude)…each time a read some new data I try display the map in that point using theRouteDraw() and also to draw a line between the points that I read.

The following code is working!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

public class screen_database extends MapActivity {

private LocationManager lm;

private LocationListener locationListener;

private MyLocationOverlay myLocOverlay;

private MapView mapView;

private MapController mc;

DBAdapter db;

InitTask init_task;

GeoPoint p;

GeoPoint progress1[];

List<GeoPoint> geoPointsArray = new ArrayList<GeoPoint>();

GeoPoint srcPlace;

GeoPoint destPlace;


double latitude;
double longitude;
private ProgressDialog progress;
MotionEvent event;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.screen_database);
    db = new DBAdapter(this);

    progress = new ProgressDialog(this);
    progress.setIndeterminate(true);
    progress.setMessage("I am thinking");

    initMap();
    // initMyLocation();
    // theRouteDraw();

}

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

private void initMap() {
    mapView = (MapView) findViewById(R.id.mapview);
    mapView.setBuiltInZoomControls(true);
    mapView.setStreetView(true);

    mc = mapView.getController();

}

public void onResume() {
    super.onResume();
    init_task = new InitTask();
    init_task.execute(db);

}

public void theRouteDraw(GeoPoint p) {
    mc.animateTo(p);
    mc.setZoom(17);
    mapView.setSatellite(true);
    mapView.setStreetView(true);
    mapView.invalidate();

}

class myOverlay extends Overlay {
    GeoPoint gp1;
    GeoPoint gp2;

    public myOverlay(GeoPoint gp1, GeoPoint gp2) {

        this.gp1 = gp1;
        this.gp2 = gp2;

    }

    public void draw(Canvas canvas, MapView mapView, boolean shadow) {

        Projection projection = mapView.getProjection();
        Paint mPaint = new Paint();
        Point from = new Point();
        projection.toPixels(gp1, from);
        mPaint.setColor(Color.BLUE);

        Point to = new Point();
        projection.toPixels(gp2, to);
        mPaint.setStrokeWidth(9);
        mPaint.setAlpha(120);

        canvas.drawLine(from.x, from.y, to.x, to.y, mPaint);
        super.draw(canvas, mapView, shadow);

    }

}

public class InitTask extends AsyncTask<DBAdapter, GeoPoint, Void> {
    List<GeoPoint> geoPointsArray = new ArrayList<GeoPoint>();
    DBAdapter db;
    int latitude;
    int longitude;
    GeoPoint p;

    protected void onPreExecute() {
        progress.show();
    }

    protected Void doInBackground(DBAdapter... db) {
        try {
            db[0].openDataBase();
            Cursor c = db[0].getAllData();

            if (c.moveToFirst()) {

                do {

        longitude =Integer.parseInt(c.getString(1));


                            latitude = Integer.parseInt(c.getString(2));

                    p = new GeoPoint(latitude, longitude);

                    geoPointsArray.add(p);

                    publishProgress(p);

                    Thread.sleep(1500);
                } while (c.moveToNext());

            }
            c.close();
            db[0].close();

        } catch (Exception e) {
            Log.d("Eroare", "doInBackground", e);
        }

        return null;
    }

    protected void onProgressUpdate(GeoPoint... progress1) {


        try{

        if(geoPointsArray.size()==1){

            mapView.getOverlays().add(new myOverlay(geoPointsArray.get(1),geoPointsArray.get(1)));

            theRouteDraw(progress1[0]);
        }

                        } 

              catch(Exception e){

                  e.printstack();
                             }

        if (geoPointsArray.size() > 1) {

        int i = geoPointsArray.size();

            List overlays = mapView.getOverlays();

            overlays.add(new myOverlay(geoPointsArray.get(i - 1),
                    progress1[0]));

            theRouteDraw(progress1[0]);
        }

geoPointsArray.add(progress1[0]);
}

}

protected void onPause() {

    init_task.cancel(true);

    super.onPause();
}

}

  • 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-22T01:00:50+00:00Added an answer on May 22, 2026 at 1:00 am

    the reason you don’t see a line on the map is because when you create the new myOverlay with the two GeoPoints, you’re actually using the same two points. In this line:

    mapView.getOverlays().add(new myOverlay(geoPointsArray.get(1),geoPointsArray.get(1)));
    

    its obvious that the same point is being added as the from and to points – which I guess is okay when you only have 1 point in the array (this is your start point). However, the code:

    overlays.add(new myOverlay(geoPointsArray.get(i - 1), progress1[0]));
    

    is also using the same point, since you just added the new point progress1[0] to the geoPointsArray in this line which comes before:

    geoPointsArray.add(progress1[0]);
    

    So canvas.drawLine won’t produce a visible result.

    If you move the line above to the end of the method then you won’t be using the same point for gp1 and gp2 in the myOverlay constructor. You will have to sort out the sequencing a bit. I used an array of pre-constructed GeoPoints instead of getting them from the database and I found that the AsyncTask was a bit unpredictable – here’s a screen-shot of my attempt (the map doesn’t show because I’m not using my correct map API key:

    enter image description here

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
In order to apply a triggered animation to all ToolTip s in my app,
I want use html5's new tag to play a wav file (currently only supported
I want to count how many characters a certain string has in PHP, but
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
Seemingly simple, but I cannot find anything relevant on the web. What is the

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.