谷歌地图没有显示在谷歌地图api v2中

时间:2013-11-19 07:01:01

标签: android google-maps google-maps-android-api-2 google-maps-api-2

您好我正在尝试使用谷歌提供的代码运行地图应用程序,但地图未显示,它显示昨天现在我的设备上显示一个空白屏幕

当我运行程序时,以下是日志

logcat的

01-02 11:33:36.203: D/dalvikvm(20623): GC_CONCURRENT freed 188K, 10% free 7589K/8391K, paused 17ms+10ms, total 86ms
01-02 11:33:36.203: D/dalvikvm(20623): WAIT_FOR_CONCURRENT_GC blocked 43ms
01-02 11:33:36.789: D/dalvikvm(20623): GC_CONCURRENT freed 343K, 11% free 7817K/8775K, paused 12ms+2ms, total 68ms
01-02 11:33:36.789: D/dalvikvm(20623): WAIT_FOR_CONCURRENT_GC blocked 31ms
01-02 11:33:36.789: D/dalvikvm(20623): WAIT_FOR_CONCURRENT_GC blocked 31ms
01-02 11:33:36.789: D/dalvikvm(20623): WAIT_FOR_CONCURRENT_GC blocked 31ms
01-02 11:33:36.789: D/dalvikvm(20623): WAIT_FOR_CONCURRENT_GC blocked 32ms
01-02 11:33:36.789: D/dalvikvm(20623): WAIT_FOR_CONCURRENT_GC blocked 33ms
01-02 11:33:36.796: D/dalvikvm(20623): WAIT_FOR_CONCURRENT_GC blocked 36ms
01-02 11:33:36.937: D/AbsListView(20623): Get MotionRecognitionManager
01-02 11:33:37.007: D/dalvikvm(20623): GC_CONCURRENT freed 255K, 11% free 8050K/8967K, paused 17ms+3ms, total 59ms
01-02 11:33:37.039: E/GooglePlayServicesUtil(20623): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
01-02 11:33:37.109: D/libEGL(20623): loaded /vendor/lib/egl/libEGL_POWERVR_SGX540_120.so
01-02 11:33:37.125: D/libEGL(20623): loaded /vendor/lib/egl/libGLESv1_CM_POWERVR_SGX540_120.so
01-02 11:33:37.132: D/libEGL(20623): loaded /vendor/lib/egl/libGLESv2_POWERVR_SGX540_120.so
01-02 11:33:37.242: D/OpenGLRenderer(20623): Enabling debug mode 0
01-02 11:33:37.492: D/dalvikvm(20623): GC_FOR_ALLOC freed 267K, 11% free 8188K/9159K, paused 35ms, total 35ms
01-02 11:33:37.539: D/dalvikvm(20623): GC_CONCURRENT freed 327K, 12% free 8318K/9351K, paused 3ms+2ms, total 32ms
01-02 11:33:37.539: D/dalvikvm(20623): WAIT_FOR_CONCURRENT_GC blocked 20ms
01-02 11:33:37.570: D/dalvikvm(20623): GC_FOR_ALLOC freed 453K, 13% free 8191K/9351K, paused 21ms, total 21ms
01-02 11:33:37.679: D/dalvikvm(20623): GC_CONCURRENT freed 304K, 11% free 8335K/9351K, paused 17ms+40ms, total 105ms

它显示未安装谷歌播放服务。但我安装了播放服务并将其导入我的eclipse工作区,我使用

将其添加到我的项目中
  

项目的属性-机器人

这是我的清单文件

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

    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="18" />

    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true"/>
     <permission
    android:name="com.googlemap.permission.MAPS_RECEIVE"
    android:protectionLevel="signature"/>

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




    <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.googlemap.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>
         <meta-data
    android:name="com.google.android.maps.v2.API_KEY"
    android:value="My api key"/>

         <meta-data android:name="com.google.android.gms.version" 
             android:value="@integer/google_play_services_version" />

    </application>

</manifest>

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.SupportMapFragment"/>

MainActivity.java

package com.googlemap;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import com.google.android.gms.maps.CameraUpdateFactory;
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;

public class MainActivity extends FragmentActivity {
    GoogleMap map;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        if (map == null) {
         map = ((SupportMapFragment)  getSupportFragmentManager().findFragmentById(R.id.map))
                   .getMap();
         LatLng loc = new LatLng(8.557845, 76.880727);

            map.setMyLocationEnabled(true);

            map.moveCamera(CameraUpdateFactory.newLatLngZoom(loc, 13));

            map.addMarker(new MarkerOptions()
                    .title("Google map")
                    .snippet(" IT city .")
                    .position(loc));
        }
    }

} 

project.properties文件

target=Google Inc.:Google APIs:17
android.library=false
android.library.reference.1=../google-play-services_lib

请帮助我。我尝试了一些解决方案,但我没有得到结果 提前谢谢..

2 个答案:

答案 0 :(得分:2)

The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.

您似乎没有正确设置Google Play服务。

按照以下链接中的步骤操作并设置Google Play服务。

http://developer.android.com/google/play-services/setup.html

您还需要检查Google Play服务的可用性。请查看以下链接中的检查Google Play服务主题。

http://developer.android.com/training/location/receive-location-updates.html

你的min sdk是14

<uses-sdk
    android:minSdkVersion="14"

因此,您需要使用MapFragment代替SupportMapFrament

更改为

<?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"/>

替换

public class MainActivity extends FragmentActivity {

通过

public class MainActivity extends Activity {

更改

map = ((SupportMapFragment)  getSupportFragmentManager().findFragmentById(R.id.map))
               .getMap();

map = ((MapFragment)  getFragmentManager().findFragmentById(R.id.map))
               .getMap();

答案 1 :(得分:1)

请参阅此处,只需使用清单文件中的密钥更改api密钥,然后按照以下步骤操作: 并且确保使用android清单文件中提到的包名称生成api密钥,并且google_play_services_lib项目应仅存在于项目的工作空间中。

清单文件:              

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

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

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

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

        <meta-data
    android:name="com.google.android.maps.v2.API_KEY"
    android:value="replace with your API key"/>

    </application>

</manifest>

MainActivity.java:

    package com.geeklabs.map;

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

public class MainActivity extends Activity {

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

}

activity_main.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"/>

得到这个后告诉我。