我使用的是之前的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" />
我在Manifest中添加了以下内容 -
<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);
}}
答案 0 :(得分:0)
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="com.example.towntour.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<permission
android:name="com.temp.android.maps.googlev2.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.temp.android.maps.googlev2.permission.MAPS_RECEIVE" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@android:style/Theme.Black.NoTitleBar" >
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyDp6PHK3NYNwS74cKGmX-xc4LuH_uM1mIo" />
<activity
android:name="com.temp.android.SplashScreenActivity"
android:label="@string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
答案 1 :(得分:0)
Use This XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
答案 2 :(得分:0)
This Way will be usefull for that..
public class HelloGoogleMaps extends MapActivity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
MapView mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
}
}
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.maps.MapView
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="API_KEY"
/>
<uses-library android:name="com.google.android.maps"/>
<uses-permission android:name="android.permission.INTERNET"/>