尝试全屏加载Google地图时遇到问题。 我已经关注了pub.dartland.org中所有有关map_view的文档:
在我的AndroidManifest.xml中,
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
还添加了:
<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="your_api_key"/>
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version"/>
当然更改了apiKey,并且:
<activity android:name="com.apptreesoftware.mapview.MapActivity" android:theme="@style/Theme.AppCompat.Light.DarkActionBar"/>
我还在build.graddle中添加了kotlin依赖项。 因此,现在我可以在设备上看到staticUri地图,很好,但是当我点击此地图以全屏显示时,应用程序因以下错误而崩溃:
D/AndroidRuntime( 4373): Shutting down VM
E/AndroidRuntime( 4373): FATAL EXCEPTION: main
E/AndroidRuntime( 4373): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.apptreesoftware.mapview.MapActivity}: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class fragment
E/AndroidRuntime( 4373): Caused by: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class fragment
E/AndroidRuntime( 4373): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
E/AndroidRuntime( 4373): Caused by: java.lang.RuntimeException: API key not found. Check that <meta-data android:name="com.google.android.geo.API_KEY" android:value="your API key"/> is in the <application> element of AndroidManifest.xml
我尝试添加:
<meta-data android:name="com.google.android.geo.API_KEY" android:value="xxxxxxxxxxxxxxx"/>
但同样的问题,也许有人有主意吗?
编辑: 这是我的AndroidManifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<application
android:name="io.flutter.app.FlutterApplication"
android:label="my-app"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<meta-data
android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
android:value="true" />
<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="XXXXXXXXXXXXXX"/>
<!-- <meta-data android:name="com.google.android.geo.API_KEY" android:value="XXXXXXXXXXXXXXXX"/> -->
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version"/>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name="com.apptreesoftware.mapview.MapActivity" android:theme="@style/Theme.AppCompat.Light.DarkActionBar"/>
</application>
</manifest>
答案 0 :(得分:1)
好的,您需要将google maps元数据移到activity
标签之外,如下所示:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<application
android:name="io.flutter.app.FlutterApplication"
android:label="my-app"
android:icon="@mipmap/ic_launcher">
<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="XXXXXXXXXXXXXX"/>
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version"/>
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<meta-data
android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
android:value="true" />
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name="com.apptreesoftware.mapview.MapActivity" android:theme="@style/Theme.AppCompat.Light.DarkActionBar"/>
</application>
</manifest>
您可以在此处找到更多信息:
https://developer.android.com/guide/topics/manifest/meta-data-element
总而言之,元数据与父组件有关,因此在这种情况下,您需要用于所有应用程序的元数据,而不仅仅是用于一项活动:)。