0

我使用的是以前的 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);
}}
4

3 回答 3

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"/>
于 2013-07-15T13:36:58.703 回答
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>
于 2013-07-15T11:18:42.153 回答
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" />

于 2013-07-15T11:47:54.993 回答