为什么谷歌地图没有出现在Android应用程序中?

时间:2014-04-22 18:14:08

标签: java android xml google-maps

当我尝试打开谷歌地图活动时,我的导航应用程序崩溃了。在我看来,谷歌地图代码可能有一些问题。地图活动的代码如下。任何人都可以帮我吗?

enter image description here

enter image description here

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

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

    <permission
        android:name="com.uit.awamimarkaz.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />

    <uses-permission android:name="com.uit.awamimarkaz.permission.MAPS_RECEIVE" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

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

    <supports-screens
        android:largeScreens="true"
        android:normalScreens="true"
        android:smallScreens="true"
        android:xlargeScreens="true" />

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

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

        <activity
            android:name="com.uit.awamimarkaz.Splash"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".Sel_Dest"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="com.uit.CLEARSCREEN" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:name=".Sel_Process"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="com.uit.Sel_Process" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:name=".Map_Cnic"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="com.uit.Map_Cnic" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:name=".Map_Passport"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="com.uit.Map_Passport" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:name=".Map_Others"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="com.uit.Map_Others" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:name=".Online_Map"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="com.uit.Online_Map" />

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

</manifest>

        Online_Map.java
package com.uit.awamimarkaz;
import android.os.Bundle;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
public class Online_Map extends MapActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.online_map);
        MapView mapView;
        mapView = (MapView) findViewById(R.id.map);

        mapView.setBuiltInZoomControls(true);
    }

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

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

2 个答案:

答案 0 :(得分:0)

您至少缺少API密钥。请完全按照以下链接,您应该没有问题让基本地图工作。

https://developers.google.com/maps/documentation/android/start#getting_the_google_maps_android_api_v2

答案 1 :(得分:0)

右键单击您的项目。

1)转到“属性”。

2)从左侧栏中选择Android

3)选择Project build target to Google API而不是Android API

<强>更新

请在清单文件

中的应用程序标记下面的行下面

<uses-library android:name="com.google.android.maps" />

希望你会发现它很有用。