开发者

Google Map MapOverlay Problem

My problem is I am displaying Google Map with PushPin on Particular Location but in my application if user can click on the pushpin the location name is display in toast or text-view, but i don't know how to do this?

Please Help me.

Following is my Code:-

Map_Activity.java:-

public class Map_Activity extends MapActivity {

    String mArea;
    MapView mapView;
    MapController mc;
    GeoPoint p;
    String[] mLongitude,mLatitude,mAreaArray;
    double lat,lng;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.google_map_screen);

        Bundle bdl=getIntent().getExtras();
        mArea= bdl.getString("Area Name");

        mAreaArray=getResources().getStringArray(R.array.PlaceName);
        mLongitude=getResources().getStringArray(R.array.Longitude);
        mLatitude=getResources().getStringArray(R.array.Latitude);

        for(int i=0;i<mAreaArray.length;i++){
            if(mArea.equals(mAreaArray[i])){
                lat=Float.valueOf(mLatitude[i]);
                lng=Float.valueOf(mLongitude[i]);
            }
        }

        mapView = (MapView) findViewById(R.id.googlemap);
        LinearLayout zoomLayout = (LinearLayout) findViewById(R.id.zoom);
        @SuppressWarnings("deprecation")
        View zoomView = mapView.getZoomControls();

        zoomLayout.addView(zoomView, new LinearLayout.LayoutParams(
                LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
        mapView.displayZoomControls(true);

        mc = mapView.getController();

        p = new GeoPoint((int) (lat * 1E6), (int) (lng * 1E6));

        mc.animateTo(p);
        mc.setZoom(17);
        MapOverlay mapOverlay = new MapOverlay();
        List<Overlay> listOfOverlays = mapView.getOverlays();
        listOfOverlays.clear();
        listOfOverlays.add(mapOverlay);
        mapView.invalidate();

    }

    @Override
    protected boo开发者_运维百科lean isRouteDisplayed() {
        // TODO Auto-generated method stub
        return false;
    }

    public boolean onKeyDown(int keyCode, KeyEvent event) {
        MapController mc = mapView.getController();
        switch (keyCode) {
        case KeyEvent.KEYCODE_3:
            mc.zoomIn();
            break;
        case KeyEvent.KEYCODE_1:
            mc.zoomOut();
            break;
        }
        return super.onKeyDown(keyCode, event);
    }

    class MapOverlay extends com.google.android.maps.Overlay {
        @Override
        public boolean draw(Canvas canvas, MapView mapView, boolean shadow,
                long when) {
            super.draw(canvas, mapView, shadow);

            // ---translate the GeoPoint to screen pixels---
            Point screenPts = new Point();
            mapView.getProjection().toPixels(p, screenPts);

            // ---add the marker---
            Bitmap bmp = BitmapFactory.decodeResource(getResources(),
                    R.drawable.pushpin);
            canvas.drawBitmap(bmp, screenPts.x, screenPts.y - 50, null);
            return true;
        }

        @Override
        public boolean onTap(GeoPoint p, MapView mapView) {
            // TODO Auto-generated method stub
            Toast.makeText(Google_Map_Activity.this, "Sorry Don't Click", Toast.LENGTH_SHORT).show();
            return super.onTap(p, mapView);
        }
    }
}


follow these links:

http://developer.android.com/guide/tutorials/views/hello-mapview.html

http://www.vogella.de/articles/AndroidLocationAPI/article.html


Follow the bellow link. This provides detailed explanation for all the steps.

http://mobiforge.com/developing/story/using-google-maps-android

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜