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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:26:16+00:00 2026-06-05T06:26:16+00:00

This is MapOverlay: class MapOverlay extends com.google.android.maps.Overlay { @Override public boolean draw(Canvas canvas, MapView

  • 0

This is MapOverlay:

class MapOverlay extends com.google.android.maps.Overlay
{
    @Override
    public boolean draw(Canvas canvas, MapView mapView, 
    boolean shadow, long when) 
    {

            return true;

    }


    @Override
    public boolean onTouchEvent(MotionEvent event, MapView mapView) 
    {   
        //---when user lifts his finger---
        if (event.getAction() == 1) {                
            GeoPoint p = mapView.getProjection().fromPixels(
                (int) event.getX(),
                (int) event.getY());


            List<Overlay> mapOverlays = mapView.getOverlays();
            Drawable drawable = getResources().getDrawable(R.drawable.splash_logo);
            ItemizedOverlay itemizedoverlay = new ItemizedOverlay(drawable, getApplicationContext());

            OverlayItem overlayitem = new OverlayItem(p, "I'm in LA!");
            itemizedoverlay.addOverlay(overlayitem);
            mapOverlays.add(itemizedoverlay);

            mapView.invalidate();

            Geocoder geoCoder = new Geocoder(
                getBaseContext(), Locale.getDefault());
            try {
                List<Address> addresses = geoCoder.getFromLocation(
                    p.getLatitudeE6()  / 1E6, 
                    p.getLongitudeE6() / 1E6, 1);

                 String add = "";
                if (addresses.size() > 0) 
                {
                    for (int i=0; i<addresses.get(0).getMaxAddressLineIndex(); 
                         i++)
                       add += addresses.get(0).getAddressLine(i) + "\n";
                }

                //Toast.makeText(getBaseContext(), add, Toast.LENGTH_SHORT).show();
                addr = add;
            }
            catch (IOException e) {                
                e.printStackTrace();
            }   

            return true;
        }
        else                
            return false;
    }        
}

This is ItemizedOverlay:

class ItemizedOverlay extends com.google.android.maps.ItemizedOverlay<OverlayItem>{


    private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
    private Context mContext;

    public ItemizedOverlay(Drawable defaultMarker) {
     super(boundCenterBottom(defaultMarker));
    // TODO Auto-generated constructor stub
    }
    public ItemizedOverlay(Drawable defaultMarker, Context context) {
      super(boundCenterBottom(defaultMarker));
      mContext = context;
    }

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

    @Override
    public int size() {
      return mOverlays.size();
    }

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

    public void removeOverlay(OverlayItem overlay) {
        mOverlays.remove(overlay);
        populate();
    }

    public void clear() {
        mOverlays.clear();
        populate();
    }

    @Override
    protected boolean onTap(int index) {
      OverlayItem item = mOverlays.get(index);
      AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
      dialog.setTitle(item.getTitle());
      dialog.setMessage(item.getSnippet());
      dialog.show();
      return true;
    }

}

I’m able to add more than one item overlay with this but not able to call clear so that as to remove the itemziedoverylay item.

What I want to do is this: When I touch on a particular point of the map, the previous itemized overlays should be deleted and a new one at that point should be created. I know I’ve to call clear() but not able to figure out where exactly should I do it.

  • 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-05T06:26:18+00:00Added an answer on June 5, 2026 at 6:26 am

    Hi you have to write this code in your mapoverlay Class

    if (itemizedoverlay != null) {
    itemizedoverlay.overlayClear();
    }

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

Sidebar

Related Questions

This is my MVC model: public class Link { [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public Guid ID {
I've tried to mark multiple locations on my mapview. There is, a class extends
I'm using http://developer.android.com/resources/tutorials/views/hello-mapview.html#top tutorial to show multi location in the map using markers.but it
This is my MapActivity Class, it should read the address from the string, reverse
I have a task to show 458 markers to show in Android maps. And
How do I display users current location in my app, using google maps? I
I wrote an application that shows google maps and some wi-fi places for my
I followed the instructions from the google hellomapview tutorial. I get a working mapview
I want to draw a circle on MapView, i.e. radius. I do it like
I have set up a MapView Class which has Overlays (and they're working fine.)

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.