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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:21:41+00:00 2026-06-15T04:21:41+00:00

Possible Duplicate: How to add an image in mapview balloon? this is a code

  • 0

Possible Duplicate:
How to add an image in mapview balloon?

this is a code which show image from url how do i give image from my res/drawable folder? this is a https://github.com/jgilfelt/android-mapviewballoons code i used please tell me how i give my own images istead of url

 public class CustomMap extends MapActivity {

MapView mapView;
List<Overlay> mapOverlays;
Drawable drawable;
Drawable drawable2;
CustomItemizedOverlay<CustomOverlayItem> itemizedOverlay;
CustomItemizedOverlay<CustomOverlayItem> itemizedOverlay2;

@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    mapView = (MapView) findViewById(R.id.mapview);
    mapView.setBuiltInZoomControls(true);

    mapOverlays = mapView.getOverlays();

    // first overlay
    drawable = getResources().getDrawable(R.drawable.marker);
    itemizedOverlay = new CustomItemizedOverlay<CustomOverlayItem>(drawable,  
   mapView);

    GeoPoint point = new GeoPoint((int)(51.5174723*1E6),(int)(-0.0899537*1E6));
    CustomOverlayItem overlayItem = new CustomOverlayItem(point, "Tomorrow  
   Never Dies (1997)", 
            "(M gives Bond his mission in Daimler car)", 
            "http://ia.media-imdb.com/images 
 5BMTM1MTk2ODQxNV5BMl5BanBnXkFtZTcwOTY5MDg0NA@@._V1._SX40_CR0,0,40,54_.jpg");
    itemizedOverlay.addOverlay(overlayItem);

    GeoPoint point2 = new GeoPoint((int)(51.515259*1E6),(int)(-0.086623*1E6));
    CustomOverlayItem overlayItem2 = new CustomOverlayItem(point2,  
    "GoldenEye    (1995)", 
            "(Interiors Russian defence ministry council chambers in  
St Petersburg)", 
            "http://ia.media-imdb.com 


  images5BMzk2OTg4MTk1NF5BMl5BanBnXkFtZTcwNj
ExNTgzNA@@._V1._SX40_CR0,0,40,54_.jpg");        
    itemizedOverlay.addOverlay(overlayItem2);

    mapOverlays.add(itemizedOverlay);

    // second overlay
    drawable2 = getResources().getDrawable(R.drawable.marker2);
    itemizedOverlay2 = new CustomItemizedOverlay<CustomOverlayItem>
   (drawable2,    mapView);

    GeoPoint point3 = new GeoPoint((int)(51.513329*1E6),(int)(-0.08896*1E6));
    CustomOverlayItem overlayItem3 = new CustomOverlayItem(point3, "Sliding 
   Doors (1998)", 
            "(interiors)", null);
    itemizedOverlay2.addOverlay(overlayItem3);

    GeoPoint point4 = new GeoPoint((int)(51.51738*1E6),(int)(-0.08186*1E6));
    CustomOverlayItem overlayItem4 = new CustomOverlayItem(point4, "Mission:  
  Impossible (1996)", 
            "(Ethan & Jim cafe meeting)", 
            "http://ia.media- 
      imdb.coimagesV5BMjAyNjk5Njk0MV5BMl5BanBnXkFtZTcwOT
 A4MjIyMQ@@._V1._SX40_CR0,0,40,54_.jpg");       
    itemizedOverlay2.addOverlay(overlayItem4);

    mapOverlays.add(itemizedOverlay2);

    final MapController mc = mapView.getController();
    mc.animateTo(point2);
    mc.setZoom(16);

  }

@Override
protected boolean isRouteDisplayed() {
    return false;
}

         }







                     public class CustomOverlayItem extends OverlayItem {

protected String mImageURL;

public CustomOverlayItem(GeoPoint point, String title, String snippet, String  
         imageURL) {
    super(point, title, snippet);
    mImageURL = imageURL;
}

public String getImageURL() {
    return mImageURL;
}

public void setImageURL(String imageURL) {
    this.mImageURL = imageURL;
}

             }




                    public class CustomBalloonOverlayView<Item extends OverlayItem> 
       extends BalloonOverlayView<CustomOverlayItem> {

private TextView title;
private TextView snippet;
private ImageView image;

public CustomBalloonOverlayView(Context context, int balloonBottomOffset) {
    super(context, balloonBottomOffset);
}

@Override
protected void setupView(Context context, final ViewGroup parent) {

    // inflate our custom layout into parent
    LayoutInflater inflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View v = inflater.inflate(R.layout.balloon_overlay_example2, parent);

    // setup our fields
    title = (TextView) v.findViewById(R.id.balloon_item_title);
    snippet = (TextView) v.findViewById(R.id.balloon_item_snippet);
    image = (ImageView) v.findViewById(R.id.balloon_item_image);

}

@Override
protected void setBalloonData(CustomOverlayItem item, ViewGroup parent) {

    // map our custom item data to fields
    title.setText(item.getTitle());
    snippet.setText(item.getSnippet());

    // get remote image from network.
    // bitmap results would normally be cached, but this is good enough for  
         demo purpose.
    image.setImageResource(R.drawable.icon);
    new FetchImageTask() { 
        protected void onPostExecute(Bitmap result) {
            if (result != null) {
                image.setImageBitmap(result);
            }
        }
    }.execute(item.getImageURL());

}

private class FetchImageTask extends AsyncTask<String, Integer, Bitmap> {
    @Override
    protected Bitmap doInBackground(String... arg0) {
        Bitmap b = null;
        try {
             b = BitmapFactory.decodeStream((InputStream) new  
       URL(arg0[0]).getContent());
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } 
        return b;
    }   
}

     }
  • 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-15T04:21:42+00:00Added an answer on June 15, 2026 at 4:21 am

    The easy way

    1. Change CustomOverlayItem class. If you don’t want load image from URL, you can change String mImageURL to int drawableId. And create getter and setter for this variable and new contructor.

      public class CustomOverlayItem extends OverlayItem {
      
      protected String mImageURL;
      private int drawableId;
      
      
      
      public CustomOverlayItem(GeoPoint point, String title, String snippet, int drawableId) {
          super(point, title, snippet);
          this.drawableId = drawableId;
      }
      
      public CustomOverlayItem(GeoPoint point, String title, String snippet, String imageURL) {
          super(point, title, snippet);
          mImageURL = imageURL;
      }
      
      
      public int getDrawableId() {
          return drawableId;
      }
      
      public void setDrawableId(int drawableId) {
          this.drawableId = drawableId;
      }
      
      public String getImageURL() {
          return mImageURL;
      }
      
      public void setImageURL(String imageURL) {
          this.mImageURL = imageURL;
      }
      

      }

    2. In setBalloonData method of CustomBalloonOverlayView class, change it to

      @Override
      protected void setBalloonData(CustomOverlayItem item, ViewGroup parent) {
      
      // map our custom item data to fields
      title.setText(item.getTitle());
      snippet.setText(item.getSnippet());
      
      // get remote image from network.
      // bitmap results would normally be cached, but this is good enough for demo purpose.
      image.setImageResource(item.getDrawableId()); // you set your image from drawable here.
      
      Here is where you load image from URL. So comment or remove it.
      /*new FetchImageTask() { 
          protected void onPostExecute(Bitmap result) {
              if (result != null) {
                  image.setImageBitmap(result);
              }
           }
      }.execute(item.getImageURL());*/ }
      
    3. In CustomMap, change the way you create overlay

       CustomOverlayItem overlayItem = new CustomOverlayItem(point, "Tomorrow Never Dies (1997)", 
                  "(M gives Bond his mission in Daimler car)", 
                  R.drawable.marker); // pass your drawable here  instead of URL.
      

    If you want to keep method load URL, you must modify BalloonOverlayView too.

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

Sidebar

Related Questions

Possible Duplicate: How to add .php extension using .htaccess url rewriting? I want to
Possible Duplicate: add “readonly” to <input > (jQuery) This is so weird, I hope
Possible Duplicate: PHP code can insert image to excel file and open it correctly
Possible Duplicate: add values to enum Why enums in Java cannot inherit from other
Possible Duplicate: Get Variable from httpcontext coming from NSUrlRequest This question will be a
Possible Duplicate: Why do some websites add “Slugs” to the end of URLs? This
Possible Duplicate: delphi non visual component image How to add my icon to my
Possible Duplicate: Add a field and insert an increment value I have this table
Possible Duplicate: How to add background image on iphone Navigation bar? I am looking
Possible Duplicate: How can I add loading text/image to images that are still loading

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.