【问题标题】:Google-maps-api is not loaded at all in android appGoogle-maps-api 根本没有在 android 应用程序中加载
【发布时间】:2018-09-30 05:45:04
【问题描述】:

我有一个带有 Google 地图活动的 android 应用程序,调试版本的效果非常好,但发布版本根本无法加载地图。活动已启动,但地图未显示。

这是发布版本的 Google Maps Activity 的 SS:

有人知道怎么了?

这是活动 xml:

<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="com.renovaciontabasco.gouapp.UbiActivity" />

google_maps_api.xml:

 <string name="google_maps_key" templateMergeStrategy="preserve" translatable="false">YOUR_KEY_HERE</string>

还有java文件:

import android.app.Activity;
import android.app.Dialog;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.UiSettings;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

public class UbiActivity extends FragmentActivity implements OnMapReadyCallback {

    static double longitud;
    static double latitud;

    private GoogleMap mMap;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ubi);
       // Obtain the SupportMapFragment and get notified when the map is ready to be used.

        int status= GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
        if(status== ConnectionResult.SUCCESS){
        SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);
        } else {
            Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status,(Activity)getApplicationContext(),10);
            dialog.show();
        }

        SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);
    }

   public static void direccion(double longi, double lat){
       longitud = longi;
       latitud = lat;
   }

/**
 * Manipulates the map once available.
 * This callback is triggered when the map is ready to be used.
 * This is where we can add markers or lines, add listeners or move the camera. In this case,
 * we just add a marker near Sydney, Australia.
 * If Google Play services is not installed on the device, the user will be prompted to install
 * it inside the SupportMapFragment. This method will only be triggered once the user has
 * installed Google Play services and returned to the app.
 */
@Override
   public void onMapReady(GoogleMap googleMap) {
       mMap = googleMap;

       mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);

       UiSettings uiSettings = mMap.getUiSettings();
       uiSettings.setZoomControlsEnabled(true);
       LatLng locUniv = new LatLng(latitud,longitud);
       mMap.addMarker(new MarkerOptions().position(locUniv).title("Universidad"));
       float zoomlevel = 16;
       mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(locUniv,zoomlevel));
   }
}

【问题讨论】:

    标签: android google-maps android-studio android-activity google-maps-api-3


    【解决方案1】:

    问题不在java 文件中,而是在谷歌服务的应用设置中

    如果您使用的是 firebase,请尝试添加您的发布密钥库的 sha1 总和

    还要看日志里面一定有信息

    编辑

    同时签入https://console.developers.google.com/apis/credentials?project=...

    你已经在OAuth 2.0 customer IDs设置了Android客户端

    例如

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-10-03
      • 1970-01-01
      • 1970-01-01
      • 2017-01-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多