限制OSMdroid上的MapView区域

时间:2012-12-28 09:38:44

标签: java android android-mapview osmdroid

我正在尝试限制OSM的地图视图,因为4点可以作为核心。

在参考这个question时,我也试图使用BoundedMapView.java(从这个website得到)来帮助我。

这是我的活动代码:

public class POfflineMapView extends Activity implements LocationListener, MapViewConstants{

    private BoundedMapView myOpenMapView;
    //... removed unreleated variables
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    mResourceProxy = new DefaultResourceProxyImpl(getApplicationContext());
    setContentView(R.layout.offline_map_activity);
    myOpenMapView = (BoundedMapView) findViewById(R.id.openmapview);
    myOpenMapView.getTileProvider().clearTileCache();

    //removed unlreleated codes

    BoundingBoxE6 bbox = new BoundingBoxE6(north,east,south,west);
    myOpenMapView.setScrollableAreaLimit(bbox);
    }
}   

这是我的xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

    <entity.BoundedMapView
        android:id="@+id/openmapview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"/>
</LinearLayout>

我的LogCat显示此错误:

12-28 17:24:11.830: E/AndroidRuntime(14459): Caused by: java.lang.NoSuchMethodException: <init> [class android.content.Context, interface android.util.AttributeSet]

我不确定为什么我仍然会收到此错误; BoundedMapView是从MapView类扩展的,为什么它仍然有构造函数的错误?

如果我似乎没有正确解释这个错误,请启发,谢谢!

1 个答案:

答案 0 :(得分:1)

这是因为当你在xml代码中创建BoundedMapView时,它会调用这个缺少的构造函数:

public BoundedMapView(final Context context, final AttributeSet attrs) {
    super(context, 256, new DefaultResourceProxyImpl(context), null, null, attrs);
}