0

我有一个 google map android api v2 项目,但我在手机上运行这个项目,logcat 有错误

加载地图失败。联系 Google 服务器时出错。这可能是身份验证问题(但可能是由于网络错误)

所以我的代码在这里

在课堂上的 HomeActivity

package com.mpa.emvi;

import com.mpa.emvi.R;
import android.support.v4.app.FragmentActivity;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

import android.os.Bundle;
//import android.app.Activity;
import android.view.Menu;

public class HomeActivity extends FragmentActivity {

    private GoogleMap mMap;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);
        setUpMapIfNeeded();
    }

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

    private void setUpMapIfNeeded() {
        // Do a null check to confirm that we have not already instantiated the map.
        if (mMap == null) {
            // Try to obtain the map from the SupportMapFragment.
            mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
                    .getMap();
            // Check if we were successful in obtaining the map.
            if (mMap != null) {
                setUpMap();
            }
        }
    }

    private void setUpMap() {
        mMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker"));
    }

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

}

这是一个布局 HomeActivity

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/send"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".HomeActivity" >

    <fragment xmlns:map="http://schemas.android.com/apk/res-auto"
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerHorizontal="true"/>

    <Button
        android:id="@+id/sendDS"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/map"
        android:layout_centerHorizontal="true"
        android:text="@string/send_destination"/>

</RelativeLayout>

这是一个清单文件

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.mpa.emvi"
    android:versionCode="2"
    android:versionName="2.1.0">
    <permission
    android:name="com.mpa.emvi.permission.MAPS_RECEIVE"
    android:protectionLevel="signature"/>
  <uses-permission android:name="com.mpa.emvi.permission.MAPS_RECEIVE"/>
  <!-- Copied from Google Maps Library/AndroidManifest.xml. -->
  <uses-sdk
        android:minSdkVersion="11"
        android:targetSdkVersion="14"/>
  <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"/>
  <!-- External storage for caching. -->
  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
  <!-- My Location -->
  <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
  <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
  <!-- Maps API needs OpenGL ES 2.0. -->
  <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.mpa.emvi.HomeActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <meta-data android:name="com.google.android.maps.v2.API_KEY"
        android:value="My-Release-API-KEY"/>
    </application>

</manifest>

你看我的代码。你有什么事吗?好的,我尝试在此解决相同的问题,并尝试重新生成新的 api 密钥但不起作用。在我的项目中,导入一个谷歌服务库和安卓支持 v4。在谷歌控制台中,我打开谷歌地图 android api v2 服务。在谷歌控制台安卓应用程序中:my-SHA1-serials;com.mpa.emvi

好吧,我是一个新手 android 程序员,很抱歉我的英语很差。

感谢每一个答案。

4

2 回答 2

0

您是否在清单文件中添加了您的 Api 密钥?

于 2013-07-11T16:08:28.320 回答
0

好的,现在我的应用程序正在显示地图。我忘记删除旧的 apk 文件并重新安装新的 apk 文件它可以工作。感谢任何答案谢谢。

于 2013-07-15T04:04:33.383 回答