Android Google Map Polygon click event -


this question has answer here:

i working on map application on android , using google maps android api v2. polygon data web service, convert xml parse , can show on map without problem. isn't there way open pop-up when user touches on polygon? or maybe if user wants change coordinates of selected polygon. saw many examples, done javascript or using different third party. has advice? in advance.

i had same problem. onmapclicklistener not called when user taps polygon, it's called when other overlays (such polygons) not process tap event. polygon process it, can see - gm moves polygon center of screen. , event not passed onmapclicklistener, that's it. workaround it, intercept tap events before gm handles them, in view wrapping mapfragment, described here, project clicked point screen coordinates map, , check if inside polygon on map described here (other answer tells too)

relevant code:

public class mysupportmapfragment extends supportmapfragment { private view moriginalcontentview; private touchablewrapper mtouchview; private basicmapactivity mactivity;  @override public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     mactivity = (basicmapactivity) getactivity(); }  @override public view oncreateview(layoutinflater inflater, viewgroup parent,         bundle savedinstancestate) {     moriginalcontentview = super.oncreateview(inflater, parent,             savedinstancestate);     mtouchview = new touchablewrapper();     mtouchview.addview(moriginalcontentview);     return mtouchview; }  @override public view getview() {     return moriginalcontentview; }  class touchablewrapper extends framelayout {      public touchablewrapper() {         super(mactivity);     }      @override   public boolean dispatchtouchevent(motionevent event) {     switch (event.getaction()) {       case motionevent.action_down:           break;       case motionevent.action_up: {           int x = (int) event.getx();           int y = (int) event.gety();           mactivity.tapevent(x,y);           break;       }     }     return super.dispatchtouchevent(event);   } }  } 

basicmapactivity:

public void tapevent(int x, int y) {     log.d(tag,string.format("tap event x=%d y=%d",x,y));     if(!iseditmode()) {         projection pp = mmap.getprojection();         latlng point = pp.fromscreenlocation(new point(x, y));         (shape ss : mpolygons) {             if(ss.ispointinpolygon(point)) {                 ss.mmarkers.get(0).marker.showinfowindow();             }         }     } }  protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_map); } 

layout:

<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" >  <fragment     android:id="@+id/map"     android:layout_width="match_parent"     android:layout_height="match_parent"     class="au.com.datalink.plugins.mysupportmapfragment" />  </relativelayout> 

Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -