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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:17:58+00:00 2026-06-09T23:17:58+00:00

I was following this tutorial to create something a little diffrent, this tutorial showed

  • 0

I was following this tutorial to create something a little diffrent, this tutorial showed how the overlay works with predefined items inserted to it, but what if i want to dynamiclly add items to it? then I must start with an empty overlay:

Instead of :

MapView mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
List<Overlay> mapOverlays = mapView.getOverlays();
Drawable drawable = this.getResources().getDrawable(R.drawable.androidmarker);
ItemOverlay itemizedoverlay = new ItemOverlay(drawable, this);

GeoPoint point = new GeoPoint(19240000,-99120000);
OverlayItem overlayitem = new OverlayItem(point, "Hola, Mundo!", "I'm in Mexico City!");
itemizedoverlay.addOverlay(overlayitem);

mapOverlays.add(itemizedoverlay);

which works just like as expected in the tutorial, I need to put this:

MapView mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
List<Overlay> mapOverlays = mapView.getOverlays();
Drawable drawable = this.getResources().getDrawable(R.drawable.androidmarker);
ItemOverlay itemizedoverlay = new ItemOverlay(drawable, this);
mapOverlays.add(itemizedoverlay);

which ommits the initializition of the overlay with an item.

this approach leads to the map getting stuck, and after few taps my app gets kicked out due to null exception.

1.is this expected behavior? it seems like a bug to me…

2.what do i do in order to acheive the expected behavior?(in which i can start with an empty overlay and add items to it dynamically)

And as for what i want to acheive, which is to not initiate the overlay with and item but to use addOverlay dynamically, this way i can

  • 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-06-09T23:17:59+00:00Added an answer on June 9, 2026 at 11:17 pm

    As far as I understand, under ItemOverlay you mean ItemizedOverlay. If so, you are on the right track. ItemizedOverlay is a container of map items, so every time you add/delete items from ItemizedOverlay you need to set last focused item to -1 and call populate() method to notify mapview about content change.

    Just remember that you need to make changes in ItemizedOverlay content in a UI thread context 😉

    There is also undocumented trick here. You need to set last focused index to -1 and do populate() even when you don’t have items (so you need to do this on initialization stage)

    So your code should look like:

    MapView mapView = (MapView) findViewById(R.id.mapview);
    mapView.setBuiltInZoomControls(true);
    List<Overlay> mapOverlays = mapView.getOverlays();
    Drawable drawable = this.getResources().getDrawable(R.drawable.androidmarker);
    ItemOverlay itemizedoverlay = new ItemOverlay(drawable, this);
    mapOverlays.add(itemizedoverlay);
    
    setLastFocusedIndex(-1); //reset initial position
    populate(); //notify about our content
    
    
    //now try to add new item
    GeoPoint point = new GeoPoint(19240000,-99120000);
    OverlayItem overlayitem = new OverlayItem(point, "Hola, Mundo!", "I'm in Mexico City!");
    itemizedoverlay.addOverlay(overlayitem);
    setLastFocusedIndex(-1); //reset initial position
    populate(); //notify about our content
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm following this tutorial CSV-FILE-EXPORT-IMPORT-RAILS but something im doing wrong, because i got an
I'm following this tutorial to create a simple Hello World extension for Chrome: http://code.google.com/chrome/extensions/getstarted.html
i have made a simple php contact form following this tutorial: http://www.catswhocode.com/blog/how-to-create-a-built-in-contact-form-for-your-wordpress-theme The big
I was following this tutorial , but for the life of me I cant
I am following this tutorial . All is going well until I try create
I have followed this tutorial to configure apn_on_rails but I am getting the following
I think i'm overlooking something stupid but i'm following a rails 3 tutorial, and
I was following this tutorial to create an ElementMenu on the Microsoft Surface 2.
I'm folowing this tutorial to create php/jquery based chat application. In short, this code
I'm new to cakephp and following this tutorial. http://book.cakephp.org/2.0/en/tutorials-and-examples/blog-auth-example/auth.html I have created the blog

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.