gpt4 book ai didi

java - 谷歌地图未在 Android 应用程序上加载,应用程序运行时出现空白屏幕

转载 作者:太空宇宙 更新时间:2023-11-04 13:52:41 25 4
gpt4 key购买 nike

请找到下面的代码。

Manifest.xml --添加了所有必需的权限和 API key

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

<permission
android:name="com.achra.fma.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />


<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="com.achra.fmap.permission.MAPS_RECEIVE"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />

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



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

<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.achra.fmap.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.achra.fmap.Activity_map"/>
<activity android:name=".FMap"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar"/>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="removed key intentionally" />

</application>


</manifest>

map_view.xml --布局文件

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

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

</RelativeLayout>

Activity_Map.java

    package com.achra.fmap;

import android.app.Activity;
import android.os.Bundle;
import android.widget.Toast;

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;

public class Activity_map extends Activity {

// Google Map
private GoogleMap googleMap;

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map_view);

try {
// Loading map
initilizeMap();

} catch (Exception e) {
e.printStackTrace();
}

}

/**
* function to load map. If map is not created it will create it for you
* */
private void initilizeMap() {
if (googleMap == null) {
googleMap = ((MapFragment) getFragmentManager().findFragmentById(
R.id.map)).getMap();

// check if map is created successfully or not
if (googleMap == null) {
Toast.makeText(getApplicationContext(),
"Sorry! unable to create maps", Toast.LENGTH_SHORT)
.show();
}
}
}

@Override
protected void onResume() {
super.onResume();
initilizeMap();
}

}

我们可以在屏幕上看到 map 网格,但 map 没有出现。请进一步指导。

我们正在使用 Google Maps API v2。

最佳答案

您的 AndroidManifest.xml 中似乎缺少 com.google.android.gms.version

如果您查看日志,您可能会看到以下内容:

You must have the following declaration within the <application> element:        <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />

尝试将其添加到您的 API key 下方:

    <meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="removed key intentionally" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />

关于java - 谷歌地图未在 Android 应用程序上加载,应用程序运行时出现空白屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30145590/

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