安卓地图视图显示黑屏

3

我在我的应用程序中使用谷歌地图,但是无法获取地图瓦片,只能看到黑色屏幕。我已经苦苦挣扎了三天,我在电脑上生成了地图API密钥,并在我的manifest.xml文件中添加了所有权限,但仍然无法获取地图瓦片。

ActivityMap.java

package com.example.locatometer;

import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.Handler;

import com.example.locatometer.utils.Tracker;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;

public class ActivityMap extends MapActivity{
    MapView mapView;
    MapController controller;
    Tracker tracker;
    Handler locationHandler = new Handler();
    GeoPoint mapPoint;

    @Override
    protected void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.activity_current_location_on_map);
        init();
    }
    private void init() {
        mapView = (MapView) findViewById(R.id.map);
        mapView.setBuiltInZoomControls(true);
        mapView.setSatellite(true);
        controller = mapView.getController();

    }
    @Override
    protected void onResume() {
        super.onResume();

    }
    @Override
    protected void onPause() {
        super.onPause();

    }
    @Override
    protected boolean isRouteDisplayed() {
        return false;
    }

}
`

layout.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" >

    <com.google.android.maps.MapView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/map"
        android:clickable="true"
        android:apiKey="******************************" />

</LinearLayout>

manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.locatometer"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="5"
        android:targetSdkVersion="10" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION"/>
    <uses-permission android:name="android.permission.INTERNET"/>

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/LocatometerTheme" android:debuggable="true">
        <uses-library android:name="com.google.android.maps"/>
        <activity
            android:name="com.example.locatometer.ActivitySplash"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="com.example.locatometer.ActivityMenu"></activity>
        <activity android:name="com.example.locatometer.ActivityCurrentLocation"></activity>
        <activity android:name="com.example.locatometer.ActivityMap"></activity>
    </application>

</manifest>

和我一样,我也花了两天时间在这上面... - Alexander
1个回答

0

这可能与此无关,但当我面临类似问题时,我曾经这样做过。在您的清单文件中的应用程序标签下添加以下内容:

  android:hardwareAccelerated="false"

可能不起作用,但值得一试。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接