考虑到要充当核心的4点,我试图限制OSM的地图视图。
关于此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类扩展的,为什么它的构造方法仍然有错误?
如果我似乎无法正确解释此错误,请赐教,谢谢!
最佳答案
这是因为当您在xml代码中创建BoundedMapView
时,它将调用此构造函数,而该构造函数将丢失:
public BoundedMapView(final Context context, final AttributeSet attrs) {
super(context, 256, new DefaultResourceProxyImpl(context), null, null, attrs);
}