gpt4 book ai didi

java - Google map V2 Android 的 API key 显示为空白

转载 作者:行者123 更新时间:2023-12-02 04:55:06 25 4
gpt4 key购买 nike

我正在尝试向我的应用程序添加 map View ,但 map 显示空白屏幕,我搜索了这个问题,并添加了我需要的所有权限和 API key ,但仍然是空白。这是我的 map 代码

<com.google.android.gms.maps.MapView
android:id="@+id/map"
android:layout_width="match_parent"
android:apiKey="-----------------------------------"
android:layout_height="200dp"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:layout_marginBottom="20dp"/>

这是onCreateView中的java代码(我使用的是 fragment )

 mapview = (MapView) view.findViewById(R.id.map);
mapview.onCreate(savedInstanceState);
mapview.getMapAsync(this);

还有

 @Override
public void onMapReady(GoogleMap googleMap) {
GoogleMap map = googleMap;
map.getUiSettings().setMyLocationButtonEnabled(false);
if (ActivityCompat.checkSelfPermission(this.getContext(), android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this.getContext(), android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
map.setMyLocationEnabled(true);
GeoPoint location = user.getLocation();
LatLng pos;
if(location == null) pos = new LatLng(41.8919300, 12.5113300);
else pos = new LatLng(location.getLatitude(), location.getLongitude());
map.addMarker(new MarkerOptions().position(pos)
.title("Ti trovi qui"));
map.moveCamera(CameraUpdateFactory.newLatLngZoom(pos,10f));
mapview.onResume();

}

这是我的 list

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.diy.yourself">

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET" />
<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" />

<permission
android:name="com.diy.yourself.permissions.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.diy.yourself.permissions.MAPS_RECEIVE"/>

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat.DayNight.NoActionBar">
<activity
android:name="com.diy.yourself.SignInActivity"
android:label="Sign In"></activity>
<activity android:name="com.diy.yourself.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.diy.yourself.SignUpActivity" />

<meta-data
android:name="preloaded_fonts"
android:resource="@array/preloaded_fonts" />

<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="-----------------------------------------"/>

<uses-library android:name="com.google.android.maps"/>

<activity android:name="com.diy.yourself.ConditionsActivity" />
</application>

</manifest>

Android 版 Google map API 已启用,并且我使用的 key 是由 Firebase 自动生成且适用于其他 API 的 key ,调试器不会显示任何错误。

有人可以帮忙吗?预先感谢👍🏻

最佳答案

在 XML 中使用此代码

<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MapsActivity" />

以及此定义代码

// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this);

关于java - Google map V2 Android 的 API key 显示为空白,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56414892/

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