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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:13:41+00:00 2026-05-14T07:13:41+00:00

I am experiencing an unusual error using ItemizedOverlay in Android. I am creating a

  • 0

I am experiencing an unusual error using ItemizedOverlay in Android.

I am creating a GPS tracking device that plots a route between waypoints stored in a database.

When I provide the first two sets of longitude and latitude points through the emulator in Eclipse, it draws a red line just how I want it, but if I send another GPS point, it animates to the point, but does not draw a line from the last point.


public class MyOverlay extends ItemizedOverlay<OverlayItem> 
{

   // private Projection projection;
private Paint linePaint;
private Vector<GeoPoint> points;

public MyOverlay(Drawable defaultMarker) {
    super(defaultMarker);
    points = new Vector<GeoPoint>();
    //set colour, stroke width etc.
    linePaint = new Paint();
    linePaint.setARGB(255, 255, 0, 0);
    linePaint.setStrokeWidth(3);
    linePaint.setDither(true);
    linePaint.setStyle(Style.FILL);
    linePaint.setAntiAlias(true);
    linePaint.setStrokeJoin(Paint.Join.ROUND);
    linePaint.setStrokeCap(Paint.Cap.ROUND);

}

public void addPoint(GeoPoint point) {
    points.addElement(point);
}


public void draw(Canvas canvas, MapView view, boolean shadow) {
    int size = points.size();
    Point lastPoint = new Point();
    if(size == 0) return;
    view.getProjection().toPixels(points.get(0), lastPoint);
    Point point = new Point();
    for(int i = 1; i<size; i++){
       view.getProjection().toPixels(points.get(i), point);
        canvas.drawLine(lastPoint.x, lastPoint.y, point.x, point.y, linePaint);
        lastPoint = point;
    }
}

@Override
protected OverlayItem createItem(int arg0) {
    // TODO Auto-generated method stub
    return null;
}

@Override
public int size() {
    // TODO Auto-generated method stub
    return 0;
}
}
  • 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-14T07:13:42+00:00Added an answer on May 14, 2026 at 7:13 am

    In your code the draw() methhod is called only once and then it is never recalled. The populate method will repopulate all the overlayes points which is there in your list each time. So it will again call the draw method which will draw a line for you.

    package com.example.mymap;
    import java.util.ArrayList;
    import android.graphics.Canvas;
    import android.graphics.Paint;
    import android.graphics.Point;
    import android.graphics.drawable.Drawable;
    import com.google.android.maps.GeoPoint;
    import com.google.android.maps.ItemizedOverlay;
    import com.google.android.maps.MapView;
    import com.google.android.maps.OverlayItem;
    
    public class ItemOverLay extends ItemizedOverlay<OverlayItem> {
    
    private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
    GeoPoint prePoint=null,currentPoint=null;
    MapView mapView=null;
    Paint paint=new Paint();
    
    public ItemOverLay(GeoPoint prePoint,GeoPoint currentPoint, Drawable defaultMarker,MapView mapview) {
    
        super(boundCenterBottom(defaultMarker));
        this.currentPoint=currentPoint;
        this.prePoint = prePoint;
        mapView=mapview;
        // TODO Auto-generated constructor stub
    }
    public ItemOverLay(Drawable defaultMarker) {
        super(defaultMarker);
        // TODO Auto-generated constructor stub
    }
    
    
    public void addOverlay(OverlayItem item){
        mOverlays.add(item);
        populate();
    }
    @Override
    protected OverlayItem createItem(int i) {
         // TODO Auto-generated method stub
        return mOverlays.get(i);
    }
    
    
    
        @Override
        public void draw(Canvas canvas, MapView mapView, boolean shadow) {
    
            super.draw(canvas, mapView, shadow);
    
            Paint paint=new Paint();
            Point screenCoords=new Point();
            Point screenCoords1=new Point();
    
            mapView.getProjection().toPixels(prePoint, screenCoords);
            int x1=screenCoords.x;
            int y1=screenCoords.y;
    
            mapView.getProjection().toPixels(currentPoint, screenCoords1);
            int x2=screenCoords1.x;
            int y2=screenCoords1.y;
    
            paint.setStrokeWidth(1);
            canvas.drawLine(x1, y1, x2, y2, paint);
    
    
    
    
        }
    
            @Override
        public int size() {
            // TODO Auto-generated method stub
            return mOverlays.size();
        }
    

    }

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

Sidebar

Related Questions

I'm using Django 1.4 and experiencing an unusual problem with hidden rows in my
I am experiencing a fatal error while using artisan on the (fantastic) Laravel PHP
This is a bit of unusual problem that I'm experiencing, but recently one of
I have been investigating event fire order between browsers, because our application is experiencing
I am experiencing a problem with my circularlinkedlist. it is a list, that is
I'm experiencing issues with twitter's bootstrap-modal javascript. I'm just using the same code they
I seem to be experiencing a very unusual issue with the RichTextBox control, programming
I'm experiencing that the drawRect method is called after the modalViewController has shown. Is
I'm currently experiencing the following exception when my spring application starts: 2012-04-27 17:42:51,021 ERROR
Experiencing an issue with an Ubercart 2 store that is now running on nginx.

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.