daily pastebin goal
0%
SHARE
TWEET

Untitled

a guest Feb 11th, 2019 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.ArrayList;
  2. import android.app.AlertDialog;
  3. import android.content.Context;
  4. import android.content.DialogInterface;
  5. import android.content.Intent;
  6. import android.graphics.drawable.Drawable;
  7. import android.view.MotionEvent;
  8. import com.google.android.maps.GeoPoint;
  9. import com.google.android.maps.ItemizedOverlay;
  10. import com.google.android.maps.MapView;
  11. import com.google.android.maps.OverlayItem;
  12.  
  13. /**
  14.  * Class used to place marker or any overlay items on Map
  15.  * */
  16. public class AddItemizedOverlay extends ItemizedOverlay<OverlayItem> {
  17.  
  18.        private ArrayList<OverlayItem> mapOverlays = new ArrayList<OverlayItem>();
  19.  
  20.        private Context context;
  21.  
  22.        public AddItemizedOverlay(Drawable defaultMarker) {
  23.             super(boundCenterBottom(defaultMarker));
  24.        }
  25.  
  26.        public AddItemizedOverlay(Drawable defaultMarker, Context context) {
  27.             this(defaultMarker);
  28.             this.context = context;
  29.        }
  30.        
  31.        @Override
  32.        public boolean onTouchEvent(MotionEvent event, MapView mapView)
  33.        {  
  34.  
  35.            if (event.getAction() == 1) {
  36.                GeoPoint geopoint = mapView.getProjection().fromPixels(
  37.                    (int) event.getX(),
  38.                    (int) event.getY());
  39.                // latitude
  40.                double lat = geopoint.getLatitudeE6() / 1E6;
  41.                // longitude
  42.                double lon = geopoint.getLongitudeE6() / 1E6;
  43.                //Toast.makeText(context, "Lat: " + lat + ", Lon: "+lon, Toast.LENGTH_SHORT).show();
  44.            }
  45.            return false;
  46.        }
  47.  
  48.        @Override
  49.        protected OverlayItem createItem(int i) {
  50.           return mapOverlays.get(i);
  51.        }
  52.  
  53.        @Override
  54.        public int size() {
  55.           return mapOverlays.size();
  56.        }
  57.  
  58.        @Override
  59.        protected boolean onTap(int index) {
  60.          OverlayItem item = mapOverlays.get(index);
  61.          AlertDialog.Builder dialog = new AlertDialog.Builder(this.context);
  62.          dialog.setTitle(item.getTitle());
  63.          dialog.setMessage(item.getSnippet());
  64.          dialog.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
  65.        public void onClick(DialogInterface dialog, int which) {
  66.          
  67.          startActivity(new Intent(AddItemizedOverlay.this,SinglePlaceActivity.class));
  68.        }
  69.          })
  70.       .setNegativeButton("No",new DialogInterface.OnClickListener() {
  71.         public void onClick(DialogInterface dialog,int id) {
  72.           // if this button is clicked, just close
  73.           // the dialog box and do nothing
  74.           dialog.cancel();
  75. //          MainActivity.this.finish();
  76.         }
  77.       });
  78.          dialog.show();
  79.          return true;
  80.        }
  81.  
  82.        public void addOverlay(OverlayItem overlay) {
  83.           mapOverlays.add(overlay);
  84.        }
  85.        
  86.        public void populateNow(){
  87.          this.populate();
  88.        }
  89.  
  90.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top