谷歌地图api v2。无法加载地图。无法连接到谷歌服务器

时间:2013-04-25 09:02:05

标签: android google-maps-api-2

我在真实设备上运行应用程序时遇到此错误。

Main_Activity.java,

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    int chkGooglePlayServices = GooglePlayServicesUtil
            .isGooglePlayServicesAvailable(Context);
    if (chkGooglePlayServices != ConnectionResult.SUCCESS) {
        GooglePlayServicesUtil.getErrorDialog(chkGooglePlayServices,
                (Activity) Context, 1122).show();
    } else {
        SupportMapFragment sfm = (SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map);
        mMap = sfm.getMap();

        mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
        lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        Criteria criteria = new Criteria();
        criteria.setAccuracy(Criteria.ACCURACY_FINE);
        // Location Update
        LocationListener listener = new LocationListener() {
            @Override
            public void onLocationChanged(Location location) {
                mMap.clear();
                final CameraPosition cameraPosition = new CameraPosition.Builder()
                        .target(new LatLng(location.getLatitude(), location
                                .getLongitude())).zoom(14.0f).build();
                final CameraUpdate cameraUpdate = CameraUpdateFactory
                        .newCameraPosition(cameraPosition);
                mMap.moveCamera(cameraUpdate);
            }

            AlertDialog.Builder dialog = new AlertDialog.Builder(Context)
                    .setTitle(R.string.RemindEnableGps);
            AlertDialog alert = dialog.create();

            @Override
            public void onProviderDisabled(String provider) {
                alert.setCanceledOnTouchOutside(false);
                alert.setCancelable(true);
                alert.show();

            }

            @Override
            public void onProviderEnabled(String provider) {
                alert.dismiss();

            }

            @Override
            public void onStatusChanged(String provider, int status,
                    Bundle extras) {
            }
        };

        lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,
                listener);
        final Location mLocation = lm
                .getLastKnownLocation(LocationManager.GPS_PROVIDER);

        /*final CameraPosition cameraPosition = new CameraPosition.Builder()
                .target(new LatLng(mLocation.getLatitude(), mLocation
                        .getLongitude())).zoom(14.0f).build();
        final CameraUpdate cameraUpdate = CameraUpdateFactory
                .newCameraPosition(cameraPosition);
        mMap.moveCamera(cameraUpdate);*/
    }

}

这是我的mainifest文件,

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

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

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

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

<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.example.findproperty.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>
    <uses-library android:name="com.google.android.maps" />

    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="Given my signed key" />

   </application>

</manifest>

activity_main.xml中,

 <?xml version="1.0"?>

<fragment 
    android:id="@+id/map"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_marginBottom="30dp"
    android:layout_marginLeft="30dp"
    android:layout_marginRight="30dp"
    android:layout_marginTop="60dp"
    class="com.google.android.gms.maps.SupportMapFragment"
    android:clickable="true" />

</RelativeLayout>

我导入了该应用所需的Google Play库。 Map对象不为null。但是在logcat中显示“Google maps Api v2无法加载地图。无法连接到谷歌服务器”

我缺少什么?请有人帮忙!这是杀了我!!

1 个答案:

答案 0 :(得分:0)

你的清单暗示你已经输入了你签名的api密钥作为google api密钥,所以我假设你通过在设备上安装一个签名的apk并且没有运行通过eclipse用调试密钥签名的应用程序来测试这个。这是对的吗?

API访问这样的问题通常会导致api键出现输入错误,或者在散列过程中出现错误。

我会确保你的清单中的密钥是正确的。