OnClickListener for pushpin

前端 未结 3 1881
梦谈多话
梦谈多话 2021-01-28 08:30

Here I have used google map and an overlay. I have used an image of pushpin to point to the GeoPoint.

I want to set an OnClickListener event for the pus

3条回答
  •  渐次进展
    2021-01-28 09:01

    Thank guys, for you support... In the mean time, i solved my problem so i am posting it here, hope it will help some one else...

    package org.nip.gmap;
    
    import java.util.List;
    
    import com.google.android.maps.GeoPoint;
    import com.google.android.maps.MapActivity;
    import com.google.android.maps.MapController;
    import com.google.android.maps.MapView;
    import com.google.android.maps.Overlay;
    import com.google.android.maps.OverlayItem;
    import android.graphics.drawable.Drawable;
    import android.os.Bundle;
    
    public class Main extends MapActivity {
    
    
        /** Called when the activity is first created. */
    
        MapView map;
        MapController controller;
        List overlayList;
        int lat=0;
        int lng=0;
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
    
            map = (MapView) findViewById(R.id.mapView);
            map.setBuiltInZoomControls(true);
    
            overlayList = map.getOverlays();
            Drawable drawable = this.getResources().getDrawable(R.drawable.pushpin2);
            CustomPinpoint itemizedoverlay = new CustomPinpoint(drawable,this);
    
    
            double lat_coordinates[] ={27.700556,28.2642635,30.0018168,29.776669,29.4096819,29.4560611};
            double lng_coordinates[] ={85.3630,83.9735195,80.7382742,81.2518833,81.8115051,80.5403779};
            String place_name[] ={"kathmandu","Pokhara","Darchula","Bajhang","Bajura","Baitadi"};
            String place_info[] ={"Its an capital of Nepal","Its and tourist place of Nepal","Its one of the beautiful place in country side","CHD District Target:10 51,960, VDCs/Muncipalities reported:41/41","CHD District Target: 71,280, VDCs/Muncipalities reported: 47/47","CHD District Target:10 51,960, VDCs/Muncipalities reported:41/41","CHD District Target: 71,280, VDCs/Muncipalities reported: 7/7","CHD District Target:10 21,960, VDCs/Muncipalities reported:44/41","CHD District Target: 33,3123, VDCs/Muncipalities reported: 47/47"};
    
             try{
                for(int i=0; i

    Create new class...

    package org.nip.gmap;
    
    import java.util.ArrayList;
    
    import android.app.AlertDialog;
    import android.content.Context;
    import android.graphics.drawable.Drawable;
    
    //import com.google.android.maps.GeoPoint;
    import com.google.android.maps.ItemizedOverlay;
    import com.google.android.maps.OverlayItem;
    
    public class CustomPinpoint extends ItemizedOverlay {
    
        private ArrayList pinpoints = new ArrayList();
        private Context c;
    
    
        public CustomPinpoint(Drawable defaultMarker, Context context) {
            super(boundCenter(defaultMarker));
            c= context;
    
        }
    
    //  public CustomPinpoint(Drawable M, Context context) {
    //      
    //      this(M);
    //      c= context;
    //  }
    
        public void addOverlay (OverlayItem overlay)
        {
            pinpoints.add(overlay);
    
            populate();
        }
    
        @Override
        protected OverlayItem createItem(int i) {
            // TODO Auto-generated method stub
            return pinpoints.get(i);
        }
    
        @Override
        public int size() {
    
            // TODO Auto-generated method stub
            return pinpoints.size();
        }
        @Override
        protected boolean onTap(int index) {
            // TODO Auto-generated method stub
            OverlayItem item = pinpoints.get(index);
            AlertDialog.Builder dialog = new AlertDialog.Builder(c);
            dialog.setTitle(item.getTitle());
            dialog.setMessage(item.getSnippet());
            dialog.show();
            return true;
    
        }
    
    
    }
    

提交回复
热议问题