如何在android中创建谷歌地图

时间:2013-04-25 12:33:03

标签: google-maps

我在android.i中的新手需要创建Google Map.i尝试在模拟器中创建Google Map 从我的驱动器

  

android-sdk-windows \ add-ons \ addon-google_apis-google-16 \ samples \ MapsDemo

1)我在libs文件夹中添加了map,effect和usbs jar文件 2)我添加了许可

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.INTERNET" />

但错误的是代码
错误:

04-25 18:00:00.857: E/AndroidRuntime(2339): FATAL EXCEPTION: main
04-25 18:00:00.857: E/AndroidRuntime(2339): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.androidmap/com.example.androidmap.MainActivity}: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.androidmap/com.example.androidmap.MapsDemo}; have you declared this activity in your AndroidManifest.xml?
04-25 18:00:00.857: E/AndroidRuntime(2339):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
04-25 18:00:00.857: E/AndroidRuntime(2339):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
04-25 18:00:00.857: E/AndroidRuntime(2339):     at android.app.ActivityThread.access$600(ActivityThread.java:130)
04-25 18:00:00.857: E/AndroidRuntime(2339):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
04-25 18:00:00.857: E/AndroidRuntime(2339):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-25 18:00:00.857: E/AndroidRuntime(2339):     at android.os.Looper.loop(Looper.java:137)
04-25 18:00:00.857: E/AndroidRuntime(2339):     at android.app.ActivityThread.main(ActivityThread.java:4745)
04-25 18:00:00.857: E/AndroidRuntime(2339):     at java.lang.reflect.Method.invokeNative(Native Method)
04-25 18:00:00.857: E/AndroidRuntime(2339):     at java.lang.reflect.Method.invoke(Method.java:511)
04-25 18:00:00.857: E/AndroidRuntime(2339):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
04-25 18:00:00.857: E/AndroidRuntime(2339):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
04-25 18:00:00.857: E/AndroidRuntime(2339):     at dalvik.system.NativeStart.main(Native Method)
04-25 18:00:00.857: E/AndroidRuntime(2339): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.androidmap/com.example.androidmap.MapsDemo}; have you declared this activity in your AndroidManifest.xml?
04-25 18:00:00.857: E/AndroidRuntime(2339):     at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1541)
04-25 18:00:00.857: E/AndroidRuntime(2339):     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1416)
04-25 18:00:00.857: E/AndroidRuntime(2339):     at android.app.Activity.startActivityForResult(Activity.java:3351)
04-25 18:00:00.857: E/AndroidRuntime(2339):     at android.app.Activity.startActivityForResult(Activity.java:3312)
04-25 18:00:00.857: E/AndroidRuntime(2339):     at android.app.Activity.startActivity(Activity.java:3522)
04-25 18:00:00.857: E/AndroidRuntime(2339):     at android.app.Activity.startActivity(Activity.java:3490)
04-25 18:00:00.857: E/AndroidRuntime(2339):     at com.example.androidmap.MainActivity.onCreate(MainActivity.java:14)
04-25 18:00:00.857: E/AndroidRuntime(2339):     at android.app.Activity.performCreate(Activity.java:5008)
04-25 18:00:00.857: E/AndroidRuntime(2339):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
04-25 18:00:00.857: E/AndroidRuntime(2339):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
04-25 18:00:00.857: E/AndroidRuntime(2339):     ... 11 more

编辑:

 <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.androidmap"
    android:versionCode="1"
    android:versionName="1.0" >
    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />
   <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.INTERNET" />
    <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.example.androidmap.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> 
       <activity android:name="com.example.android.apis.MapsDemo" android:label="MapsDemo"/>
       <activity android:name="com.example.android.apis.view.MapViewDemo" android:label="MapView"/>
       <activity android:name="com.example.android.apis.view.MapViewCompassDemo" android:label="MapView and Compass"/>
           </application>
</manifest>

请帮帮我。

2 个答案:

答案 0 :(得分:2)

您需要使用MapActivity扩展Class,并确保已在Menifest.xml文件中声明它 或点击此链接获取帮助Google Maps

答案 1 :(得分:0)

您尚未在清单文件中声明活动 - 添加它们。有关Google Maps API的详情,请查看this