0

我正在尝试一个 android 地图应用程序,当我运行它时,代码中没有错误或问题,我使用我的 samsung Galaxy s3 对其进行测试,但它一直显示 >“不幸的是,地图已停止”。

这是我的java文件

package com.maps;

import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import android.os.Bundle;

public class Main extends MapActivity {

MapView map;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    map = (MapView) findViewById(R.id.mvMain);
}

@Override
protected boolean isRouteDisplayed() {
    // TODO Auto-generated method stub
    return false;
}

}

这是我的xml代码

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>

<com.maps.MapView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:apiKey="AIzaSyAfv657yXaBMlBLAe2pw0VyJiPLiczDG7E"
    android:id="@+id/mvMain"/>

</LinearLayout>

这是我的清单

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

<uses-sdk
    android:minSdkVersion="8"
  />
<uses-permission android:name="android.permission.INTERNET"/>


<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <uses-library android:name="com.google.android.maps"/>
    <activity
        android:name="com.maps.Main"
        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>

</manifest>
4

3 回答 3

0

尝试使用适用于 Android 的 Google Maps v2。在这里你有一个很好的教程。无论如何,您的问题似乎与 API 密钥有关。

于 2013-06-28T09:02:48.010 回答
0

使用地图时的崩溃通常是由于错误的 API 密钥造成的。仔细检查您使用的密钥是否有效

于 2013-06-28T08:56:42.003 回答
0

如果 GOOGLE API 无效,它就不会显示地图。您为什么不附上您的 manifest.xml 文件,以便我们纠正您的错误。否则检查清单文件是否包含 GOOGLEapi 的引用。

于 2013-06-28T09:50:15.913 回答