Android Custom MapView

I am trying to create an advanced version MapView.

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

I implement onTouchListenerInside my own custom map view.

I also want to know if there are any methods from which I can pan the mapview.

The problem does not persist when the original version of MapView is used with the 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 onTouchEvent(MotionEvent event) {
        if(event.getAction()==MotionEvent.ACTION_DOWN){
            Log.v("MyMapView","Touched");
        }

        return false ;
    }



}

my onCreate()fromMapActivity

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

}
+3
source share
2 answers

I was wrong.

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

it should be

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

This solves the problem.

Thankx anyway.

0
source

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

MapController . , :

    @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 );
}
+1

Source: https://habr.com/ru/post/1784937/


All Articles