MapFragment与谷歌播放地图api v2在Eclipse中崩溃

时间:2013-04-01 21:23:47

标签: android eclipse maps google-play-services

我是android开发的新手,每当我尝试启动此活动时,它都会崩溃。我已经尝试过只有hello world并且意图很好,我认为它可能是Manifest中的东西,但我不确定它应该如何用maps api v2形成。我发现这个问题真的令人沮丧。任何帮助深表感谢。 清单XML:

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

<uses-sdk
    android:minSdkVersion="11"
    android:targetSdkVersion="17" />

<permission
    android:name="com.eriklansner.androidprojekt.alkometer.MAPS_RECEIVE"
    android:protectionLevel="signature" />

<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" >
    <activity
        android:name="com.eriklansner.androidprojekt.alkometer.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action
                android:name="android.intent.action.MAIN"
                android:value="your_apikey" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name="com.eriklansner.androidprojekt.alkometer.Promilleutraknaren"
        android:label="@string/title_activity_promilleutraknaren" >
    </activity>
    <activity
        android:name="com.eriklansner.androidprojekt.alkometer.Activity"
        android:label="@string/title_activity_" >
    </activity>
    <activity
        android:name="com.eriklansner.androidprojekt.alkometer.MainActivityasd"
        android:label="@string/title_activity_main_activityasd" >
    </activity>
    <activity
        android:name="com.eriklansner.androidprojekt.alkometer.Activitydos"
        android:label="@string/title_activity_activitydos" >
    </activity>
    <activity
        android:name="com.eriklansner.androidprojekt.alkometer.Gelok"
        android:label="@string/title_activity_gelok" >
    </activity>
    <activity
        android:name="com.eriklansner.androidprojekt.alkometer.UseGps"
        android:label="@string/title_activity_use_gps" >
    </activity>
    <activity
        android:name="com.eriklansner.androidprojekt.alkometer.Visasvar"
        android:label="@string/title_activity_visasvar" >
    </activity>
    <activity
        android:name="com.eriklansner.androidprojekt.alkometer.DataContentProvider"
        android:label="@string/title_activity_data_content_provider" >
    </activity>
    <activity
        android:name="com.eriklansner.androidprojekt.alkometer.ColumnSchema"
        android:label="@string/title_activity_column_schema" >
    </activity>
    <activity
        android:name="com.eriklansner.androidprojekt.alkometer.TemperatureData"
        android:label="@string/title_activity_temperature_data" >
    </activity>
    <activity
        android:name="com.eriklansner.androidprojekt.alkometer.MyActivity"
        android:label="@string/title_activity_my" >
    </activity>
    <activity
        android:name="com.eriklansner.androidprojekt.alkometer.MyPlot"
        android:label="@string/title_activity_my_plot" >
    </activity>
    <activity
        android:name="com.eriklansner.androidprojekt.alkometer.SimpleXYPlotActivity"
        android:label="@string/title_activity_simple_xyplot" >
    </activity>
    <activity
        android:name="com.eriklansner.androidprojekt.alkometer.Main"
        android:label="@string/title_activity_main" >
    </activity>
    <activity
        android:name="com.eriklansner.androidprojekt.alkometer.Alkinmatning"
        android:label="@string/title_activity_alkinmatning" >
    </activity>
    <activity
        android:name="com.eriklansner.androidprojekt.alkometer.Alk"
        android:label="@string/title_activity_alk" >
    </activity>
    <activity
        android:name="com.eriklansner.androidprojekt.alkometer.Googlemapsgps"
        android:label="@string/title_activity_googlemapsgps" >
    </activity>

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

    <activity
        android:name="com.eriklansner.androidprojekt.alkometer.trolol"
        android:label="@string/title_activity_trolol" >
    </activity>
    <activity
        android:name="com.eriklansner.androidprojekt.alkometer.Map"
        android:label="@string/title_activity_map" >
    </activity>
</application>

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="com.example.mapdemo.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<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" />

activity_map.xml:

     <?xml version="1.0" encoding="utf-8"?>
     <fragment xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/map"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:name="com.google.android.gms.maps.MapFragment"/>

Map.java:

public class Map extends Activity {

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

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.activity_map, menu);
    return true;
}

}

1 个答案:

答案 0 :(得分:0)

CRASH可能的原因。

您正尝试在模拟器中运行它。

您尚未在您的Manifest.in应用程序中包含API密钥。

 <application>
 <!-- some other code in the manifest -->
  <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="YOUR_API_KEY"/>
</application>

将Map Fragment添加到Main.java

GoogleMap googleMap;
  // Getting reference to the SupportMapFragment of activity_main.xml
  MapFragment fm = (MapFragment) getFragmentManager().findFragmentById(R.id.map);

    // Getting GoogleMap object from the fragment
    googleMap = fm.getMap();

了解更多详情 查看我的博客文章,我试图总结所有需要使用Google Maps API V2 for Android构建应用程序。

  1. Solution to Problems with Maps API V2(using google_play_services_lib).
  2. Creating an Android App with Maps API V2 for minSDK=8 (Android 2.2 Froyo).
  3. Creating an Android App with Maps API V2 for minSDK=11 (Android 3.0 HoneyComb).
  4. 如果您想在模拟器 READ THIS POST.

    上运行它