removing markers in mapquest android (clearing map) -


i'm using mapquest android in application, can display markers, want able display 2 markers each time, removing existing markers if have displayed two. know how can ? here code

mainactivity.java

public class mainactivity extends navigationintentdemo {      arraylist<geopoint> points = new arraylist<geopoint>();     arraylist<geopoint> routedata = new arraylist<geopoint>();      jsonparser parser = new jsonparser();      /**      * initialize map.      */     @override     protected void init() {         setupmapview(new geopoint(40.25f, 116.5f), 12);          touchoverlay overlay = new touchoverlay();         map.getoverlays().add(overlay);     }       /**      * construct simple line overlay display on map , add overlaytaplistener      * respond tap events.      *       */         private void showlineoverlaywithpoints(arraylist<geopoint> routedata) {             paint paint = new paint(paint.anti_alias_flag);             paint.setcolor(color.red);             paint.setalpha(100);             paint.setstyle(paint.style.stroke);             paint.setstrokejoin(paint.join.round);             paint.setstrokecap(paint.cap.round);             paint.setstrokewidth(10);              lineoverlay line = new lineoverlay(paint);             line.setdata(routedata);             line.setshowpoints(true, null);             line.setkey("line #2");              line.settoucheventlistener(new lineoverlay.overlaytoucheventlistener() {                             @override                 public void ontouch(motionevent evt, mapview mapview) {                     toast.maketext(getapplicationcontext(), "line touch!", toast.length_short).show();                               }             });             this.map.getoverlays().add(line);             this.map.invalidate();         }          /**      * crude way launch navigation various locations based on clicking on map.      *      */     private class touchoverlay extends overlay {           @override         public boolean ontouchevent(motionevent event, final mapview mapview) {              drawable icon = getresources().getdrawable(r.drawable.location_marker);             defaultitemizedoverlay poioverlay = new defaultitemizedoverlay(icon);              if(event.getaction() == motionevent.action_down) {                 geopoint p = mapview.getprojection().frompixels((int)event.getx(), (int)event.gety());                 toast.maketext(getapplicationcontext(), p.getlatitude() + "," + p.getlongitude(), toast.length_long).show();                   if(points.size()<2) {                 points.add(p);                    // set geopoints , title/snippet used in annotation view                  poioverlay.additem(new overlayitem(p, "blabla", "blabla"));                  if (points.size() == 2) {                      routedata = parser.getroute(    points.get(0).getlongitude(),                                                      points.get(0).getlatitude(),                                                      points.get(1).getlongitude(),                                                     points.get(1).getlatitude(),                                                     "sps");                      if (routedata != null)                         showlineoverlaywithpoints(routedata);                     else                          log.e("error","route data error");                  } else exit(0);                 /* poioverlay.setonfocuschangelistener(new itemizedoverlay.onfocuschangelistener() {                     @override                     public void onfocuschanged(itemizedoverlay overlay, overlayitem newfocus) {                         // when focused item changes, recenter map , show info                         map.getcontroller().animateto(newfocus.getpoint());                         toast.maketext(map.getcontext().getapplicationcontext(), newfocus.gettitle() + ": " +                                  newfocus.getsnippet(), toast.length_short).show();                           }                            });*/                  map.getoverlays().add(poioverlay);                 return true;                  }                 else {                      points.clear();                 }                }              return false;         }          private void exit(int i) {             // todo auto-generated method stub          }     } } 

navigationintentdemo

public class navigationintentdemo extends mapactivity {      protected mapview map;      protected mylocationoverlay mylocationoverlay;     protected button followmebutton;      /**       * called when activity first created.       *       */     @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(getlayoutid());          followmebutton=(button)findviewbyid(r.id.followmebutton);         followmebutton.setonclicklistener(new view.onclicklistener() {             @override             public void onclick(view v) {                 mylocationoverlay.setfollowing(true);             }         });          setupmapview(new geopoint(40.25f, 116.5f), 12);         setupmylocation();         init();     }      /**      * initialize view.      */     protected void init() {         this.setupmapview(new geopoint(40.25f, 116.5f), 12);     }       protected void setupmylocation() {         this.mylocationoverlay = new mylocationoverlay(this, map);          mylocationoverlay.enablemylocation();         mylocationoverlay.runonfirstfix(new runnable() {             @override             public void run() {                 geopoint currentlocation = mylocationoverlay.getmylocation();                  map.getcontroller().animateto(currentlocation);                 map.getcontroller().setzoom(14);                 map.getoverlays().add(mylocationoverlay);                 mylocationoverlay.setfollowing(true);             }         });     }      /**      * set basic mapquest map zoom controls      */     protected void setupmapview(geopoint pt, int zoom) {         this.map = (mapview) findviewbyid(r.id.map);          // set zoom level         map.getcontroller().setzoom(zoom);          // set center point         map.getcontroller().setcenter(pt);          // enable zoom controls         map.setbuiltinzoomcontrols(true);      }      /**      * id of layout file.      * @return      */     protected int getlayoutid() {         return r.layout.activity_main;     }      @override     protected boolean isroutedisplayed() {         return false;     }      /**      * utility method getting text of edittext, if no text entered hint returned      * @param edittext      * @return      */     public string gettext(edittext edittext){         string s = edittext.gettext().tostring();         if("".equals(s)) s=edittext.gethint().tostring();         return s;     }      /**      * hides softkeyboard      * @param v      */     public void hidesoftkeyboard(view v){         //hides soft keyboard         final inputmethodmanager imm = (inputmethodmanager)getsystemservice(                 context.input_method_service);         imm.hidesoftinputfromwindow(v.getwindowtoken(), 0);     }   } 

thank you


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -