在Android中显示地图?

时间:2014-02-26 08:38:18

标签: android google-maps-api-3

我正在开发一个应用程序,我想在我的设备Android 2.3.3上显示地图,它不显示在我的日志猫中显示错误 我有步骤 从debug.keystore获取SHA1代码 在google apis控制台中创建一个新项目 注册一个新的ID 启用谷歌地图android api v2 使用输入SHA1创建一个android密钥; it.mappe(it.mappe是我的包) 获取API密钥 更新AndroidManifest文件

我的AndroidManifest

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.technowellservices.getmapv2"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="10" />
<uses-feature
    android:glEsVersion="0x00020000"
    android:required="true" />

<permission
    android:name="com.technowellservices.getmapv2.permission.MAPS_RECEIVE"
    android:protectionLevel="signature" />

<uses-permission 
  android:name="net.learn2develop.googlemaps.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<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.technowellservices.getmapv2.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="AIzaSyA-NLsxXkMDXioRUcWameZSv7SFu_UPIyI" />
</application>

.xml文件

<TextView 
    android:id="@+id/tv_location"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    />

<fragment
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@id/tv_location"
    class="com.google.android.gms.maps.MapFragment"
    />

 </RelativeLayout>

logcat的

02-26 12:53:47.773: E/AndroidRuntime(9924): java.lang.RuntimeException: Unable to    
start activity ComponentInfo{com.technowellservices.getmapv2/
com.technowellservices.getmapv2.MainActivity}: android.view.InflateException: Binary    
XML file line #13: Error inflating class fragment
02-26 12:53:47.773: E/AndroidRuntime(9924):     at      
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
02-26 12:53:47.773: E/AndroidRuntime(9924):     at   
android.app.ActivityThread.access$1500(ActivityThread.java:117)
02-26 12:53:47.773: E/AndroidRuntime(9924):     at 
android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
02-26 12:53:47.773: E/AndroidRuntime(9924):     at 
android.os.Handler.dispatchMessage(Handler.java:99)
02-26 12:53:47.773: E/AndroidRuntime(9924):     at 
android.os.Looper.loop(Looper.java:130)
02-26 12:53:47.773: E/AndroidRuntime(9924):     at 
android.app.ActivityThread.main(ActivityThread.java:3687)
02-26 12:53:47.773: E/AndroidRuntime(9924):     at 
java.lang.reflect.Method.invokeNative(Native Method)
02-26 12:53:47.773: E/AndroidRuntime(9924):     at 
java.lang.reflect.Method.invoke(Method.java:507)
02-26 12:53:47.773: E/AndroidRuntime(9924):     at 
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
02-26 12:53:47.773: E/AndroidRuntime(9924):     at 
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
02-26 12:53:47.773: E/AndroidRuntime(9924):     at 
dalvik.system.NativeStart.main(Native Method)
02-26 12:53:47.773: E/AndroidRuntime(9924): Caused by: android.view.InflateException: 
Binary XML file line #13: Error inflating class fragment
02-26 12:53:47.773: E/AndroidRuntime(9924):     at 
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:581)
02-26 12:53:47.773: E/AndroidRuntime(9924):     at 
 android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
02-26 12:53:47.773: E/AndroidRuntime(9924):     at 
 android.view.LayoutInflater.inflate(LayoutInflater.java:408)
02-26 12:53:47.773: E/AndroidRuntime(9924):     at 
android.view.LayoutInflater.inflate(LayoutInflater.java:320)
02-26 12:53:47.773: E/AndroidRuntime(9924):     at 
 com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:209)
02-26 12:53:47.773: E/AndroidRuntime(9924):     at 
android.app.Activity.setContentView(Activity.java:1657)
02-26 12:53:47.773: E/AndroidRuntime(9924):     at 
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
02-26 12:53:47.773: E/AndroidRuntime(9924):     at 
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
02-26 12:53:47.773: E/AndroidRuntime(9924): Caused by: java.lang.ClassNotFoundException: 
android.view.fragment in loader  
dalvik.system.PathClassLoader[/data/app/com.technowellservices.getmapv2-1.apk]
02-26 12:53:47.773: E/AndroidRuntime(9924):     at 
dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
02-26 12:53:47.773: E/AndroidRuntime(9924):     at  
java.lang.ClassLoader.loadClass(ClassLoader.java:551)
02-26 12:53:47.773: E/AndroidRuntime(9924):     at 
java.lang.ClassLoader.loadClass(ClassLoader.java:511)
02-26 12:53:47.773: E/AndroidRuntime(9924):     at 
android.view.LayoutInflater.createView(LayoutInflater.java:471)
02-26 12:53:47.773: E/AndroidRuntime(9924):     at 
android.view.LayoutInflater.onCreateView(LayoutInflater.java:549)
02-26 12:53:47.773: E/AndroidRuntime(9924):     at 
com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView
(PhoneLayoutInflater.java:66)
02-26 12:53:47.773: E/AndroidRuntime(9924):     at   
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)

2 个答案:

答案 0 :(得分:1)

更改此

class="com.google.android.gms.maps.MapFragment"

class="com.google.android.gms.maps.SupportMapFragment"

您缺少元标记。检查答案@

A required meta-data tag in your app's AndroidManifest.xml does not exist.

扩展FragmentActivity并使用SupportMapFragment。

可以删除

<permission
android:name="com.technowellservices.getmapv2.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission 
android:name="net.learn2develop.googlemaps.permission.MAPS_RECEIVE" />

答案 1 :(得分:1)

更改此

<uses-permission 
  android:name="net.learn2develop.googlemaps.permission.MAPS_RECEIVE" />

到这个

 <uses-permission 
      android:name="com.technowellservices.getmapv2.permission.MAPS_RECEIVE" />

清理你的项目然后重新测试..