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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:29:01+00:00 2026-05-26T15:29:01+00:00

I’m trying to draw on a map using markers. The problem I’m having is

  • 0

I’m trying to draw on a map using markers. The problem I’m having is when I try to add lots of them, then I can’t get it to run.
To illustrate my problem, let’s say I want to draw a square made of 900 smaller squares (30×30). By the way, I do need those squares, not just one big square
I’m trying to add the markers to an itemizedoverlay, then drawing it.

the code is below. Any suggestion how I could do that?
Thank you very much!!

public class MainActivity extends MapActivity {
MapView mapView;
MapController mc;
GeoPoint p;
static Context context;

int k=1;    
List<Overlay> mapOverlays;
MyItemizedOverlay itemizedoverlay;  
int[] xx,yy;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);        
    context = getApplicationContext();        
    mapView = (MapView) findViewById(R.id.mapView);
    mapView.setBuiltInZoomControls(true);        

    mc = mapView.getController();
    String coordinates[] = {"36.186382", "-112.221909"};
    double lat = Double.parseDouble(coordinates[0]);
    double lng = Double.parseDouble(coordinates[1]);
    p = new GeoPoint(
                    (int) (lat * 1E6),
                    (int) (lng * 1E6));
    mc.animateTo(p);
    mc.setZoom(10);

    mapOverlays = mapView.getOverlays();
    Drawable squareM = this.getResources().getDrawable(R.drawable.square);
    itemizedoverlay = new MyItemizedOverlay(squareM);

    int n=0;
    xx = new int[30];
    yy = new int[30];
    while(n<30){
        xx[n]=n;
        yy[n]=n;
        n++;
    }

}

protected void drawNewMarker(GeoPoint p){
    OverlayItem overlayitem = new OverlayItem(p, "", "");
    itemizedoverlay.addOverlay(overlayitem);
    mapOverlays.add(itemizedoverlay);
    mapView.postInvalidate(); 
}

protected void drawNewMarkerD(){
    Point pointP = new Point(0,0);
    mapView.getProjection().toPixels(p, pointP);
    int xoff = 20*k;
    int yoff = 20*k;
    GeoPoint pp = mapView.getProjection().fromPixels(pointP.x + xoff, pointP.y + yoff);

    OverlayItem overlayitem = new OverlayItem(pp, "", "");
    Drawable iconM = this.getResources().getDrawable(R.drawable.icon);
    iconM.setBounds(0,0, 50, 50);
    overlayitem.setMarker(iconM);
    itemizedoverlay.addOverlay(overlayitem);
    mapOverlays.add(itemizedoverlay);
    k++;
    //mapView.postInvalidate(); 
}

@Override
protected boolean isRouteDisplayed() {

    return false;
}


protected void drawGrid(int xoff, int yoff){
    GeoPoint p = newGeoPointFromOffset(xoff, yoff);
    OverlayItem overlayitem = new OverlayItem(p, "", "");
    Drawable marker = this.getResources().getDrawable(R.drawable.grid);
    marker.setBounds(0,0, 15, 15);
    overlayitem.setMarker(marker);
    itemizedoverlay.addOverlay(overlayitem);
    mapOverlays.add(itemizedoverlay);
}

protected GeoPoint newGeoPointFromOffset(int xoff, int yoff){   
    Point screenPointP = new Point(0,0);      
    mapView.getProjection().toPixels(p, screenPointP);  
    int x = 15*xoff;
    int y = 15*yoff;    
    return mapView.getProjection().fromPixels(screenPointP.x + x, screenPointP.y + y);              
}

public boolean onKeyDown(int keyCode, KeyEvent event){
    MapController mc = mapView.getController();
    switch(keyCode){
    case KeyEvent.KEYCODE_3:
        mc.zoomIn();
        break;
    case KeyEvent.KEYCODE_1:
        mc.zoomOut();
        break;
    case KeyEvent.KEYCODE_0:
        drawNewMarker(p);
        break;
    case KeyEvent.KEYCODE_9:    
        for(int r=0;r<30;r++){
            for(int s=0;s<30;s++){
                 drawGrid(r,s);
            }
        }  
        mapView.postInvalidate();           
        break;
    }       
    return super.onKeyDown(keyCode, event);
}       

}

public class MyItemizedOverlay extends ItemizedOverlay{
private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
private Context mContext;

public MyItemizedOverlay(Drawable defaultMarker) {
    super(boundCenterBottom(defaultMarker));
}

public MyItemizedOverlay(Drawable defaultMarker, Context context) {
      super(defaultMarker);
      mContext = context;
}

public void draw(android.graphics.Canvas canvas, MapView mapView,boolean shadow) {
        super.draw(canvas, mapView, false);
}

public void addOverlay(OverlayItem overlay) {
    mOverlays.add(overlay);
    populate();
}

@Override
protected OverlayItem createItem(int i) {
    return mOverlays.get(i);
}

}

  • 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-26T15:29:01+00:00Added an answer on May 26, 2026 at 3:29 pm

    There is a limit to the number of overlay items that MapView can handle. There is no official word on what this limit is, but after some while, you will see sluggish behaviour during zoom/pan.

    Some solutions are :

    • LazyLoading of MapView
    • Load only as many markers that are visible, do this based on the zoom level and span.
    • 10 overlays with 99 points are faster than 1 overlay with 900 points.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

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
We're building an app, our first using Rails 3, and we're having to build
I am trying to understand how to use SyndicationItem to display feed which is
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 using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains

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.