简体   繁体   English

Google Map Android API V2失败

[英]google map android API V2 failure

Trying to add a Map into an Android application, I already created the API key and enabled Google Map Android V2; 为了将地图添加到Android应用程序中,我已经创建了API密钥并启用了Google Map Android V2; I added the permission, the google play services version and the API key in the manifest file. 我在清单文件中添加了权限,Google Play服务版本和API密钥。 I also added the Google Plays Services lib in the project. 我还在项目中添加了Google Plays Services库。

But when I launch the application it stops, I don't know why, I think it's something that has to do with the permissions, but just to make sure, I copy/Past the permissions as suggested by the Google Developpers website showing us how to add the map. 但是,当我启动该应用程序时,它停止了,我不知道为什么,我认为这与权限有关,只是为了确保我按照Google Developpers网站的建议复制/粘贴了权限,向我们展示了如何添加地图。 But like I said, I'm not sure if this si the real deal. 但是就像我说的那样,我不确定这是否是真正的交易。 Here's my codes: 这是我的代码:

Manifest file: 清单文件:

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

    <uses-sdk
        android:minSdkVersion="11"
        android:targetSdkVersion="19" />


<!-- ============  PERMISSIONS: ============ -->
<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"/>
<!-- 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"/>

 <!-- ============ END PERMISSIONS =============== -->
            <!-- this will notify the user that the device needs OpenGL ES version 2 to display the map (as recomanded from the google developpers website)-->
    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true"/>
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.Black.NoTitleBar" >
<!-- ====   google play services version:  ====  -->
    <meta-data
         android:name="com.google.android.gms.version"
         android:value="@integer/google_play_services_version" />

        <activity
            android:name="usthb.appusthb.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>

<!-- Google Map Android API V2 === ==== ===  API key:  -->
        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="AIzaSyCfqonheoI9OG_REcsnl7-xgmpiFwu692I"/>

    </application>

</manifest>

MainLayout: MainLayout:

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

MainActivity: 主要活动:

public class MainActivity extends FragmentActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toast.makeText(this, "sup", 2000).show();
    }
}

Log: 日志:

02-17 10:50:11.928: E/AndroidRuntime(1356): FATAL EXCEPTION: main
02-17 10:50:11.928: E/AndroidRuntime(1356): Process: usthb.appusthb, PID: 1356
02-17 10:50:11.928: E/AndroidRuntime(1356): java.lang.RuntimeException: Unable to start activity ComponentInfo{usthb.appusthb/usthb.appusthb.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
02-17 10:50:11.928: E/AndroidRuntime(1356):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at android.app.ActivityThread.access$800(ActivityThread.java:135)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at android.os.Handler.dispatchMessage(Handler.java:102)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at android.os.Looper.loop(Looper.java:136)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at android.app.ActivityThread.main(ActivityThread.java:5017)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at java.lang.reflect.Method.invokeNative(Native Method)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at java.lang.reflect.Method.invoke(Method.java:515)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at dalvik.system.NativeStart.main(Native Method)
02-17 10:50:11.928: E/AndroidRuntime(1356): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
02-17 10:50:11.928: E/AndroidRuntime(1356):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at android.view.LayoutInflater.inflate(LayoutInflater.java:469)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at android.app.Activity.setContentView(Activity.java:1929)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at usthb.appusthb.MainActivity.onCreate(MainActivity.java:12)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at android.app.Activity.performCreate(Activity.java:5231)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
02-17 10:50:11.928: E/AndroidRuntime(1356):     ... 11 more
02-17 10:50:11.928: E/AndroidRuntime(1356): Caused by: java.lang.SecurityException: The Maps API requires the additional following permissions to be set in the AndroidManifest.xml to ensure a correct behavior:
02-17 10:50:11.928: E/AndroidRuntime(1356): <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
02-17 10:50:11.928: E/AndroidRuntime(1356):     at maps.af.ch.a(Unknown Source)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at maps.af.ay.a(Unknown Source)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at maps.af.ay.a(Unknown Source)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at maps.af.al.a(Unknown Source)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at maps.af.bg.a(Unknown Source)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at maps.af.bf.a(Unknown Source)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at ebt.onTransact(SourceFile:107)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at android.os.Binder.transact(Binder.java:361)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at com.google.android.gms.maps.internal.IMapFragmentDelegate$a$a.onCreateView(Unknown Source)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at com.google.android.gms.maps.MapFragment$a.onCreateView(Unknown Source)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at com.google.android.gms.dynamic.a$4.b(Unknown Source)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at com.google.android.gms.dynamic.a.a(Unknown Source)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at com.google.android.gms.dynamic.a.onCreateView(Unknown Source)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at com.google.android.gms.maps.MapFragment.onCreateView(Unknown Source)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at android.app.Fragment.performCreateView(Fragment.java:1700)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:866)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1040)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at android.app.FragmentManagerImpl.addFragment(FragmentManager.java:1142)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at android.app.Activity.onCreateView(Activity.java:4786)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
02-17 10:50:11.928: E/AndroidRuntime(1356):     ... 20 more

Change this 改变这个

 android:name="com.google.android.gms.maps.MapFragment"/>

to

 android:name="com.google.android.gms.maps.SupportMapFragment"/>

since your min sdk is 11. So you need to use SupportMapFragment . 因为您的最小sdk是11。所以您需要使用SupportMapFragment For 12 and above use MapFragment . 对于12及以上版本,请使用MapFragment

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM