Google地图未显示在我的应用中

时间:2015-03-08 14:33:46

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

我最近一直在更新我的应用,现在我的谷歌地图没有显示出来。它只是用加号和减号按钮显示空白而没有别的。

我的地图片段是:

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>

4 个答案:

答案 0 :(得分:3)

我遇到了同样的问题,这是因为API密钥。默认情况下,我使用debug.keystore来生成SHA-1 key,我从谷歌获得了API密钥,我在开发时使用了它。一旦应用程序签名,那么地图就无法工作,因此您必须使用用于签署应用程序的相同keystore文件生成SHA-1密钥。

答案 1 :(得分:1)

我认为您还需要在清单应用标记中使用此功能来启用Google Play服务:

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

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

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

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

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

答案 2 :(得分:0)

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

答案 3 :(得分:0)

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

link应该可以帮到你。

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