【问题标题】:Google Map not showing up in my app谷歌地图未显示在我的应用程序中
【发布时间】:2015-03-08 14:33:45
【问题描述】:

我最近更新了我的应用程序,但现在我的谷歌地图没有显示。它只是用加号和减号按钮显示为空白,没有其他任何内容。

我的地图片段是:

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;

public class BreweryTappedMap extends Fragment {

    public BreweryTappedMap(){}

    String beerId = "";
    GoogleMap mMap;
    private SupportMapFragment fragment;
    private GoogleMap map;
    String userID;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        View rootView = inflater.inflate(R.layout.activity_brewmap, container, false);
        setHasOptionsMenu(true);
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
        String userName = prefs.getString("userName", null);
        userID = prefs.getString("userID", null);
        return rootView;
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        FragmentManager fm = getChildFragmentManager();
        fragment = (SupportMapFragment) fm.findFragmentById(R.id.map);
        if (fragment == null) {
            fragment = SupportMapFragment.newInstance();
            fm.beginTransaction().replace(R.id.map, fragment).commit();
        }
    }

    @Override
    public void onResume() {
        super.onResume();
        if (map == null) {
            map = fragment.getMap();
            String url = "myMap";

            new GetVisitedBreweries(getActivity(), map).execute(url);        }
    }
}

xml布局是:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:map="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <RelativeLayout
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    </RelativeLayout>
</RelativeLayout>

我的安卓清单:

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

    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true"/>

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

    <!-- Permission to write to external storage -->
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission android:name="android.permission.CALL_PHONE" />


    <application
        android:allowBackup="true"
        android:icon="@drawable/logo"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

        <activity android:label="@string/app_name" android:name="com.example.mike.beerportfoliomaterial.MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>

                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>

        <receiver android:name="com.example.mike.beerportfoliomaterial.HelloWidget" android:label="Beer of the Day">
            <intent-filter> <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
                <action android:name="android.appwidget.action.APPWIDGET_ENABLED" />
            </intent-filter>

            <meta-data android:name="android.appwidget.provider" android:resource="@xml/hello_widget_provider" />

        </receiver>

        <receiver android:name="com.example.mike.beerportfoliomaterial.SearchWidget" android:label="Search ">
            <intent-filter>
                <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
                <action android:name="android.appwidget.action.APPWIDGET_ENABLED" />
            </intent-filter>

            <meta-data android:name="android.appwidget.provider" android:resource="@xml/search_widget" />

        </receiver>

        <activity android:label="@string/app_name" android:name="com.example.mike.beerportfoliomaterial.LogIn">
            <intent-filter>
                <category android:name="android.intent.category"/>
            </intent-filter>
        </activity>

        <activity android:label="@string/app_name" android:name="com.example.mike.beerportfoliomaterial.Register" android:screenOrientation="portrait">
            <intent-filter>
                <category android:name="android.intent.category"/>
            </intent-filter>
        </activity>

        <activity android:label="@string/app_name" android:name="com.example.mike.beerportfoliomaterial.MainDraw" android:screenOrientation="portrait">
            <intent-filter>
                <category android:name="android.intent.category"/>
            </intent-filter>
        </activity>
        <activity android:label="@string/app_name" android:name="com.example.mike.beerportfoliomaterial.MainDrawer2" android:screenOrientation="portrait">
            <intent-filter>
                <category android:name="android.intent.category"/>
            </intent-filter>
        </activity>
        <meta-data android:name="com.crashlytics.ApiKey" android:value="myKey"/>

        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="myMapsKey"/>

    </application>
</manifest>

【问题讨论】:

  • 你的 android:value="myMapsKey" 还有效吗?

标签: android google-maps android-maps-v2


【解决方案1】:

我遇到了同样的问题,这是因为 API 密钥。默认情况下,我使用debug.keystore 生成SHA-1 key,并从Google 获得了API 密钥,我在开发时使用了它。应用签名后,地图将无法工作,因此您必须使用用于签名应用的相同 keystore 文件生成 SHA-1 密钥。

【讨论】:

  • 这是最近的变化吗?
  • 检查一下,我的问题是在我的 API 开发人员控制台中,他们的密钥与我的应用程序的新包名称不匹配。我用一个新的包名重建了我的应用程序。
【解决方案2】:

我认为您还需要在清单应用程序标签中使用它来启用 Google Play 服务:

     <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />

以下是如何将其添加为库:

http://developer.android.com/google/play-services/setup.html

对我来说,添加这个在我的 /app/gradle 依赖项中起作用:

编译'com.google.android.gms:play-services:+'

【讨论】:

  • 您是否已将 Google Play 服务库添加到您的项目中?
【解决方案3】:

您需要使用证书进行构建。在您这样做之前,Google 不会在您的应用上“浪费”其地图资源:)。

这个link 应该可以帮助你。

您是否在libs 文件夹中复制了所需的库?

【讨论】:

    【解决方案4】:

    如果您收到@integer/google_play_services_version,这通常意味着您尚未将 Google Play 服务库添加到您的项目中。

    【讨论】:

    猜你喜欢
    • 2017-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-27
    • 2019-07-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多