Android Google Map V2 Display Blank and show only zoom button?

纵饮孤独 提交于 2019-12-04 03:47:00

Probably there is a problem with your Maps API Key. Put this function into your activity, and see what it logs for the correct SHA key:

 private void getShaKey() {

 try {
 PackageInfo info = getPackageManager().getPackageInfo("your.package.name",
 PackageManager.GET_SIGNATURES);
 for (Signature signature : info.signatures) {
 MessageDigest md = MessageDigest.getInstance("SHA");
 md.update(signature.toByteArray());
 Log.v(TAG, "KeyHash:" + Base64.encodeToString(md.digest(),
 Base64.DEFAULT));
 }
 } catch (NameNotFoundException e) {
 e.printStackTrace();

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

 }

 }
denispyr

In case you tried the map example from sdk extras, you may find this answer helpful.

There Also the probability to be name package problem used for android key generation

This prints out the signature and package name that you need to enter in Google Developers Console to generate API key:

private void getShaKey() {
    try {
      Activity activity = this; // or getActivity() if the code is in fragment
      String packageName = activity.getPackageName();
      PackageInfo info = activity.getPackageManager().getPackageInfo(packageName, PackageManager.GET_SIGNATURES);
      for (android.content.pm.Signature signature : info.signatures) {
        MessageDigest md = MessageDigest.getInstance("SHA1");
        md.update(signature.toByteArray());
        byte[] digest = md.digest();
        Log.v(LOG_TAG, "KeyHash: " + bytesToHex(digest) + ";" + packageName);
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

  public static String bytesToHex(byte[] bytes) {
    char[] hexArray = "0123456789ABCDEF".toCharArray();
    char[] hexChars = new char[bytes.length * 2];
    for (int j = 0; j < bytes.length; j++) {
      int v = bytes[j] & 0xFF;
      hexChars[j * 2] = hexArray[v >>> 4];
      hexChars[j * 2 + 1] = hexArray[v & 0x0F];
    }
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < hexChars.length; i += 2) {
      sb.append(hexChars[i]);
      sb.append(hexChars[i + 1]);
      if (i < hexChars.length - 2) {
        sb.append(':');
      }
    }
    return sb.toString();
  }

Look for KeyHash: in the logs.

This is modification of Analizer's code.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!