开发者

Android Custom MapView

开发者 https://www.devze.com 2023-02-04 07:48 出处:网络
I am trying to create an extended version of MapView. The problem is when extended version of MapView is defined, mapview does not pan.

I am trying to create an extended version of MapView.

The problem is when extended version of MapView is defined, mapview does not pan.

I am implementing an onTouchListener Inside my custom map view.

I also want to know is there any methods from where I can pan the mapview.

The problem does not persist when stock version of MapView is used with same source code.

EDIT

MyMapView source:

public class MyMapView extends MapView{

    public MyMapView(Context context, String apiKey) {
        super(context, apiKey);

    }
    public MyMapView(Context context, AttributeSet attrs) {
        super(context, attrs);

    }
    public MyMapView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);

    }

    @Override
    public boolean onTou开发者_如何学GochEvent(MotionEvent event) {
        if(event.getAction()==MotionEvent.ACTION_DOWN){
            Log.v("MyMapView","Touched");
        }

        return false ;
    }



}

my onCreate() from MapActivity

protected void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.mapper);
    mMapView=(MyMapView) findViewById(R.id.mapper_map);
    mMapView.setSatellite(false);       

}


Your onTouchEvent() should return false, otherwise it will consume the event.

You can also instantiate a MapController and use it to change the view. Here's a code snippet from an app I'm working on:

    @Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.mapview);

    myMapView = (MapView) findViewById( R.id.myMapView );
    myMapView.setBuiltInZoomControls( true );
    myMapController = myMapView.getController();

    myPoint = new GeoPoint(0, 0);
    myMapController.setCenter( myPoint );
    myMapController.zoomToSpan( 360 * MILLION, 360 * MILLION );
}


I was casting it wrong.

mMapView=(MyMapView) findViewById(R.id.mapper_map); 

should be

mMapView=(MapView) findViewById(R.id.mapper_map); 

This solves the issue.

Thankx anyways.

0

精彩评论

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