gpt4 book ai didi

google-maps - 无法在 Flutter 上全屏加载 map_view

转载 作者:IT王子 更新时间:2023-10-29 06:40:35 32 4
gpt4 key购买 nike

当我尝试全屏加载谷歌地图时遇到问题。我已经关注了 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 map ,很好,但是当我点击这张 map 以全屏显示时,应用程序崩溃并出现此错误:

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>

最佳答案

好的,您需要将 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

总之,元数据与父组件相关,因此在这种情况下,您需要所有应用程序的元数据,而不仅仅是一个 Activity :)。

关于google-maps - 无法在 Flutter 上全屏加载 map_view,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52580419/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com