0

当我在 android 中单击地图中的某个位置时,它会显示警报对话框?您想将该位置保存到特定列表中,例如我的位置或收藏夹,以便我可以将该位置移动到特定列表中。

提前致谢......

4

2 回答 2

3
public class MapViewer extends MapActivity {

MapView mapView;

MapController mapController;

GeoPoint mgeoPoint;

Drawable marker;

MyLocationOverlay mLocationOverlay;

MotionEvent e;


@Override
protected void onCreate(Bundle icicle) {

    // TODO Auto-generated method stub
    super.onCreate(icicle);
    setContentView(R.layout.main);

    mapView = (MapView) findViewById(R.id.mapView);

    mapController = mapView.getController();

    mapView.setBuiltInZoomControls(true);

    mapView.setStreetView(true);


    marker = getResources().getDrawable(R.drawable.pushpin);

    marker.setBounds(0, 0, marker.getIntrinsicWidth(), marker
            .getIntrinsicHeight());

    mapView.getOverlays().add(new MapOverlay(marker));


    mLocationOverlay = new MyLocationOverlay(this, mapView);
    mapView.getOverlays().add(mLocationOverlay);

    setViewLocation();
}


@Override
protected Dialog onCreateDialog(int id) {

    // TODO Auto-generated method stub

    switch (id) {
        case 0:
            return new AlertDialog.Builder(this).setTitle("Hello").setIcon(
                    R.drawable.ic_launcher).setPositiveButton("Yes",
                    new OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog , int which) {

                            // TODO Auto-generated method stub

                        }
                    }).setCancelable(true).setNegativeButton("Cancel",
                    new OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog , int which) {

                            // TODO Auto-generated method stub

                        }
                    })

            .setOnCancelListener(new OnCancelListener() {

                @Override
                public void onCancel(DialogInterface dialog) {

                    // TODO Auto-generated method stub
                    Toast.makeText(getApplicationContext(), "Dismiss",
                            Toast.LENGTH_SHORT).show();
                }

            }).create();


        default:
            break;
    }
    return null;
        }


private void setViewLocation() {



    String[] coordinates = { "22.716221", "75.896816" };

    double lat = Double.parseDouble(coordinates[0]);
    double lng = Double.parseDouble(coordinates[1]);
    mgeoPoint = new GeoPoint((int) (lat * 1E6), (int) (lng * 1E6));

    mapController.animateTo(mgeoPoint);
    mapController.setZoom(15);

    mapView.invalidate();

}


@Override
protected boolean isRouteDisplayed() {

    // TODO Auto-generated method stub
    return false;
}


Point scrPoint;


private GeoPoint getPoint(double lat , double lon) {

    return (new GeoPoint((int) (lat * 1E6), (int) (lon * 1E6)));
}


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

    List<OverlayItem> ListofGeopoints = new ArrayList<OverlayItem>();


    public MapOverlay(Drawable defaultMarker ) {

        super(defaultMarker);

        ListofGeopoints.add(new OverlayItem(getPoint(22.716221, 75.896816),
                "IN", "India"));

        populate();

    }


    @Override
    protected boolean onTap(int index) {

    switch (index) {
            case 0:
                Toast.makeText(getApplicationContext(), "GeoLocation : 0",
                        Toast.LENGTH_LONG).show();
                showDialog(0);
            break;
        }

        return true;
    }


    String add = "";

    List<Address> add_List = new ArrayList<Address>();


    private void getAddress() {

        add_List = ReverseGeocode
                .getFromLocation(35.594227, -105.223618, 2);

    }


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


    @Override
    public int size() {
        return ListofGeopoints.size();
    }
}
}
于 2012-05-03T06:50:04.197 回答
1

您是否尝试过覆盖您的 customOverlays 中的 onTap 方法?

public class CustomOverlays extends ItemizedOverlay<OverlayItem>
{
    @Override
    public boolean onTap(GeoPoint arg0, MapView arg1) {
        // TODO Auto-generated method stub
        return super.onTap(arg0, arg1);
    }
}
于 2012-05-02T14:39:41.150 回答