java - 不可能使用 Google Map API V2 开发简单的 Android 应用程序

标签 java android eclipse google-maps google-play-services

我想在当前的应用程序中使用 Google map 。在将其集成到我的应用程序之前,我创建了一个测试项目来了解其功能。

我读到了这个:https://developers.google.com/maps/documentation/android/start#installing_the_google_maps_android_v2_api

还有这个: http://developer.android.com/google/play-services/setup.html#

在出现很多这些错误的问题之后:

didn't find class com.google.android.gms.maps.MapFragment

Found 2 versions of android-support-v4.jar in the dependency list, but not all the versions are identical (check is based on SHA-1 only at this time)

当我运行我的项目时,Eclipse 说“启动测试:(99%)”,然后我的计算机温度高达 100°C,Eclipse 占用了我的 CPU 的 512%!所以我不得不强制 Eclipse 退出。

我花了很多时间在堆栈溢出、重建、清理、添加支持库、删除项目和从头开始重新创建等方面。 帮助我,我只想创建一个基本的应用程序来测试 GoogleMap!

我的代码:

MainActivity.java

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

list

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

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

    <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" />
    <!--
     The following two permissions are not required to use
     Google Maps Android API v2, but are recommended.
    -->
    <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=".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.gms.version"
            android:value="@integer/google_play_services_version" />
        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="***" />
    </application>

</manifest>

编辑:我现在知道当我将 google-play-services_lib 引用到我的项目时会出现问题...有什么想法吗?

最佳答案

public class YourActivity extends FragmentActivity {

   GoogleMap map;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.your_activity);
        map =((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.iqamah_map)).getMap();

    }
}

你的xml:

 <?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/iqamah_map"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:name="com.google.android.gms.maps.SupportMapFragment" />

将此添加到您的 list

    <uses-permission android:name="com.example.test.permission.MAPS_RECEIVE" />
 <uses-library android:name="com.google.android.maps" />

关于java - 不可能使用 Google Map API V2 开发简单的 Android 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28604295/

相关文章:

android - eclipse ADT 图形布局

java - 如何使用 Firebase 身份验证正确登录?

java - Guice 注入(inject)根据每个请求创建的上下文实例

java - getText() 在 sendKeys() 之后返回空字符串

android - eclipse:Maven POM 文件在 "android"XML View 中打开

eclipse - 为什么 Eclipse 在本地主机端口 13405 上运行 Web 应用程序?

java - 谷歌地图 GPS : longitude and latitude returns zero

android - onPageSelected 在 vi​​ewPager.setCurrentItem 上被静态调用

android - ListView 不显示项目

android - 如何检测在android中按下按钮的时间