我使用的是以前的 Maps API - 在为 Maps v2 API 插入以下代码片段后,地图无法加载。CustomMapView 是继承 MapView 的 Java 类。无法理解应该替换或删除哪些所有参数?
<com.stub.android.ui.CustomMapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mapview" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:clickable="true"
android:apiKey="0xxxxxxxxxxxxxxxxxxxxx" />
我在清单中添加了以下内容 -
<permission
android:name="com.stub.android.ui.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<uses-permission android:name="com.stub.android.ui.permission.MAPS_RECEIVE" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIxxxxxxxxxxxxxxx" />
CustomMapView 类的代码
public class CustomMapView extends MapView {
public CustomMapView(Context context, String apiKey) {
super(context, apiKey);
// this.context = context;
}
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
try {
return super.dispatchTouchEvent(ev);
} catch (Exception ex) {
int zoomLevel = getZoomLevel();
getController().setZoom(zoomLevel-1);
super.setVisibility(View.GONE);
super.setVisibility(View.VISIBLE);
}
return true;
}
@Override
public void draw(Canvas canvas) {
try {
super.draw(canvas);
} catch (Exception e) {
int zoomLevel = getZoomLevel();
getController().setZoom(zoomLevel-1);
super.setVisibility(View.GONE);
super.setVisibility(View.VISIBLE);
}
}
public CustomMapView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// this.context = context;
}
public CustomMapView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean onTouchEvent(MotionEvent ev) {
System.gc();
return super.onTouchEvent(ev);
}}