Google 地图在 Android Studio Java 中显示为空

问题描述 投票:0回答:1
  • 我的 MapView 显示空地图内容,如下所示:

  • 当我在另一个全新的项目中做同样的事情时,它会正确显示地图。所以问题不在于 API 密钥,也不在于实施。

  • 我的项目中的某些内容阻止我的地图显示地图内容。

我在 Java 中的活动在全新项目中运行得很好:

public class GoogleMap extends AppCompatActivity implements OnMapReadyCallback {

    boolean isPermissionGranted;
    MapView mapView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_google_map);

        mapView = findViewById(R.id.map_view);

        checkMyPermission();

        if(isPermissionGranted){
            mapView.getMapAsync(this);
            mapView.onCreate(savedInstanceState);
        }
    }

这是该活动的 xml:

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".ui.util.GoogleMap">

    <com.google.android.gms.maps.MapView
        android:id="@+id/map_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

这些是我的依赖项,以防此处可能出现错误:

dependencies {

    implementation ("com.squareup.picasso:picasso:2.8")
    implementation("androidx.appcompat:appcompat:1.6.1")
    implementation ("com.auth0.android:jwtdecode:2.0.2")
    implementation("com.google.android.material:material:1.10.0")
    implementation("androidx.constraintlayout:constraintlayout:2.1.4")
    implementation("androidx.core:core-ktx:+")
    implementation("androidx.lifecycle:lifecycle-livedata-ktx:2.6.2")
    implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.2")
    implementation("androidx.navigation:navigation-fragment:2.7.5")
    implementation("androidx.navigation:navigation-ui:2.7.5")
    implementation ("androidx.preference:preference:1.2.1")
    implementation ("androidx.preference:preference-ktx:1.2.1")
    implementation("com.google.code.gson:gson:2.8.7")
    implementation ("com.squareup.retrofit2:retrofit:2.3.0")
    implementation("com.google.android.gms:play-services-maps:18.2.0")
    implementation ("com.squareup.retrofit2:converter-gson:2.3.0")
    implementation ("com.squareup.okhttp3:logging-interceptor:3.12.1")
    implementation ("io.jsonwebtoken:jjwt-api:0.11.3")
    implementation ("io.jsonwebtoken:jjwt-impl:0.11.3")
    implementation ("io.jsonwebtoken:jjwt-jackson:0.11.3")
    testImplementation("junit:junit:4.13.2")
    androidTestImplementation("androidx.test.ext:junit:1.1.5")
    androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
    implementation("com.github.denzcoskun:ImageSlideshow:0.1.0")
    implementation ("com.wdullaer:materialdatetimepicker:4.2.3")
    implementation("com.google.code.gson:gson:2.8.7")
    implementation ("com.squareup.retrofit2:retrofit:2.3.0")
    implementation ("com.squareup.retrofit2:converter-gson:2.3.0")
    implementation ("com.squareup.okhttp3:logging-interceptor:3.12.1")
    implementation ("com.squareup.picasso:picasso:2.8")
    androidTestImplementation("androidx.test.ext:junit:1.1.5")
    androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
    implementation ("com.karumi:dexter:6.2.2")

}
java android google-maps
1个回答
0
投票

  • 问题出在network_config.xml中。仅允许后端与 Android 应用程序通信。

  • 我添加并解决了问题。

© www.soinside.com 2019 - 2024. All rights reserved.