相信我,在发布之前我已经完成了至少十几个答案,因为他们都没有帮我解决问题,这个谷歌整合真的很恶心。
所以这是问题陈述"显示地图"就是这样。
这是迄今为止我所做的事情。
Manifiest.XML
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mapdemo"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="19"
android:targetSdkVersion="21" />
<permission
android:name="com.example.mapdemo.permission.MAPS_RECEIVE"
android:protectionLevel="signature" >
</permission>
<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" >
<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="AIzaSyCp8z8qSQdO_gFb92iru8Vyr7R7YNQglTo" />
<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>
</application>
</manifest>
activity_main.xml中
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:id="@+id/container"
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="com.example.mapdemo.MainActivity" >
</RelativeLayout>
MainActivity.java
包com.example.mapdemo;
import com.google.android.gms.maps.MapFragment;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MapFragment frag = MapFragment.newInstance();
getFragmentManager()
.beginTransaction()
.add(R.id.container, frag)
.commit();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
这是例外。
11-29 19:05:11.868: E/AndroidRuntime(19653): FATAL EXCEPTION: main
11-29 19:05:11.868: E/AndroidRuntime(19653): Process: com.example.mapdemo, PID: 19653
11-29 19:05:11.868: E/AndroidRuntime(19653): java.lang.NoClassDefFoundError: com.google.android.gms.maps.MapFragment
11-29 19:05:11.868: E/AndroidRuntime(19653): at com.example.mapdemo.MainActivity.onCreate(MainActivity.java:19)
11-29 19:05:11.868: E/AndroidRuntime(19653): at android.app.Activity.performCreate(Activity.java:5248)
11-29 19:05:11.868: E/AndroidRuntime(19653): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1110)
11-29 19:05:11.868: E/AndroidRuntime(19653): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2162)
11-29 19:05:11.868: E/AndroidRuntime(19653): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2257)
11-29 19:05:11.868: E/AndroidRuntime(19653): at android.app.ActivityThread.access$800(ActivityThread.java:139)
11-29 19:05:11.868: E/AndroidRuntime(19653): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
11-29 19:05:11.868: E/AndroidRuntime(19653): at android.os.Handler.dispatchMessage(Handler.java:102)
11-29 19:05:11.868: E/AndroidRuntime(19653): at android.os.Looper.loop(Looper.java:136)
11-29 19:05:11.868: E/AndroidRuntime(19653): at android.app.ActivityThread.main(ActivityThread.java:5086)
11-29 19:05:11.868: E/AndroidRuntime(19653): at java.lang.reflect.Method.invokeNative(Native Method)
11-29 19:05:11.868: E/AndroidRuntime(19653): at java.lang.reflect.Method.invoke(Method.java:515)
11-29 19:05:11.868: E/AndroidRuntime(19653): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
11-29 19:05:11.868: E/AndroidRuntime(19653): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
11-29 19:05:11.868: E/AndroidRuntime(19653): at dalvik.system.NativeStart.main(Native Method)
请帮帮我们,我真的失去了控制力。
我的eclipse项目buildpath和android属性的快照
谢谢, Techfist。
答案 0 :(得分:0)
&#39;在xml中使用此代码进行地图视图&#39;
<com.google.android.gms.maps.MapView android:id="@+Id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
&#39;添加您的活动&#39;
MapView mapView =(MapView) findViewById(R.id.mapView);
答案 1 :(得分:0)
哈哈哈罗夫,
所以最终,我尝试了很多混合和匹配,我甚至安装了android studio并给了那个系统一个机会,但是在浪费了2个小时之后,我甚至无法弄清楚“如何启动我的应用程序”, 最终我回到eclipse做了所有Comobs的构建,干净,改变构建路径等等。没有一个能够解决。
做了什么改变了我的工作空间,并用完全相同的代码重建项目。