谷歌地图Android API V2崩溃

时间:2015-06-26 17:30:20

标签: android eclipse google-maps-api-2

我正在尝试按照本教程使用Google Maps API V2创建应用程序: http://www.androidhive.info/2013/08/android-working-with-google-maps-v2/

我仔细阅读了本教程,但我的应用程序崩溃了。 这是我的ManifestFile(我有多个活动)

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

<permission
    android:name="com.example.philimon.permission.MAPS_RECEIVE"
    android:protectionLevel="signature" />

<uses-permission android:name="com.example.philimon.permission.MAPS_RECEIVE" />

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="19" />

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<!-- Required to show current location -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<!-- Required OpenGL ES 2.0. for Maps V2 -->
<uses-feature
    android:glEsVersion="0x00020000"
    android:required="true" />

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

    <!-- DEVELOPER'S LOADING SCREEN -->
    <activity
        android:name=".DevelopersSplashScreen"
        android:label="@string/title_activity_developers_splash_screen"
        android:screenOrientation="landscape" >


    </activity>                                 <!-- END OF ACTIVITY -->



    <!-- MONSTER ISLAND PHIL LOADING SCREEN -->
    <activity
        android:name=".PhilimonSplashScreen"
        android:label="@string/title_activity_sample"
        android:screenOrientation="landscape" >
    </activity>                                                     <!-- END OF ACTIVITY -->


    <!-- MY HOME ACTIVITY SCREEN -->
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:screenOrientation="landscape" >
    </activity>                                                      <!-- END OF ACTIVITY -->




    <activity
        android:name=".Home"
        android:label="@string/title_activity_home" 
        android:screenOrientation="landscape">
         <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

    </activity>                                                          <!-- END OF ACTIVITY -->

     <!-- Google Maps API Key -->
    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="AIzaSyCiwzjBd6Mx9Mp_tUXAezALDRnDG6kzIzo" />
</application>

我的XMl布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

<fragment
    android:id="@+id/map"
    android:name="com.google.android.gms.maps.MapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

我的Java文件:

package com.example.philimon;

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Toast;


@SuppressLint("NewApi")

public class Home extends Activity  {

// Google Map
private GoogleMap googleMap;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    try {
        // Loading map
        initilizeMap();

    } catch (Exception e) {
        e.printStackTrace();
    }


}

/**
 * function to load map. If map is not created it will create it for you
 * */
private void initilizeMap() {
    if (googleMap == null) {
        googleMap = ((MapFragment) getFragmentManager().findFragmentById(
                R.id.map)).getMap();

        // check if map is created successfully or not
        if (googleMap == null) {
            Toast.makeText(getApplicationContext(),"Sorry! unable to create maps", Toast.LENGTH_SHORT).show();
        }
    }
}

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


}

2 个答案:

答案 0 :(得分:3)

您没有添加GMS版本的元数据:

grps <- paste(un[2:10], collapse = ", ")
sprintf("%s beat out the following groups: %s in %s",un[1],grps,un[11])

答案 1 :(得分:0)

这是在Android Wear上使用谷歌Google Maps Android API v2的示例清单文件

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="your package name" >

<!-- Mark this app as an Android Wear app. -->
<uses-feature android:name="android.hardware.type.watch" />

<!-- Permissions and features required for the Android Maps API v2 -->
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

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

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.DeviceDefault" >

    <!-- API key for the Android Maps API v2. The value is defined as a string resource. -->
    <meta-data android:name="com.google.android.geo.API_KEY"
               android:value="@string/google_maps_key"/>

    <!-- Meta data required for Google Play Services -->
    <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />

    <activity
        android:name=".MainActivity"
        android:label="@string/app_name" >

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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