【问题标题】:Restrict MapView area on OSMdroid限制 OSMdroid 上的 MapView 区域
【发布时间】:2012-12-28 09:38:43
【问题描述】:

我正在尝试限制 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类扩展而来的,为什么Constructor还是报错?

如果我似乎没有正确解释此错误,请赐教,谢谢!

【问题讨论】:

    标签: java android android-mapview osmdroid


    【解决方案1】:

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

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

    【讨论】:

    • 谢谢!现在应用程序不会崩溃!但是地图及其叠加层没有再次显示,我是否又错过了什么?
    • 很难说没有看到他们的代码。清除切片缓存的那一行是什么?
    • 说构造函数不可见
    猜你喜欢
    • 2011-07-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多