显示对话框,当我在地图上的位置标记图标点击?(Display Dialog Box when i c

2019-09-16 23:06发布

当我点击了某个地方在地图android系统中它显示的警告对话框中? 你想要的位置保存到例如我的地方或最喜欢的特定列表,以便我能搬到那个地方特别列表。

提前致谢......

Answer 1:

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();
    }
}
}


Answer 2:

你试图重写方法的onTap在customOverlays?

public class CustomOverlays extends ItemizedOverlay<OverlayItem>
{
    @Override
    public boolean onTap(GeoPoint arg0, MapView arg1) {
        // TODO Auto-generated method stub
        return super.onTap(arg0, arg1);
    }
}


文章来源: Display Dialog Box when i click on the maps place marker icon?