Android Google Map V2显示空白并仅显示缩放按钮?

时间:2013-04-12 06:55:16

标签: android google-maps-android-api-2

我使用谷歌地图v2并显示多个标记  但首先我要在屏幕上显示地图 我在这里放下了我的所有文件 只给出空白我会检查出来,但对我来说没有任何作用

enter image description here

  

main.xml中

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

        <fragment
                    android:id="@+id/mapview"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    class="com.google.android.gms.maps.SupportMapFragment" />

</RelativeLayout>
  

的AndroidManifest.xml

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

    <uses-sdk
        android:minSdkVersion="10"
        />

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />  
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />        
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <permission
        android:name="com.example.stiptis.permission.MAPS_RECEIVE"
        android:protectionLevel="signature"/>
    <uses-permission android:name="com.example.stiptis.permission.MAPS_RECEIVE"/>

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.stiptis.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>
          <meta-data
                    android:name="com.google.android.maps.v2.API_KEY"
                    android:value="your api key" />
    </application>

</manifest>
  

活动类

public class MainActivity extends FragmentActivity {

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

    }



}

4 个答案:

答案 0 :(得分:6)

您的Maps API密钥可能存在问题。 将此函数放入您的活动中,并查看它记录的正确SHA密钥:

 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();

 }

 }

答案 1 :(得分:0)

如果您尝试使用sdk extras中的地图示例,您可能会发现this answer有帮助。

答案 2 :(得分:0)

安卓密钥

还有可能出现名称包问题

答案 3 :(得分:0)

这将打印出您需要在Google Developers Console中输入的签名和包名称,以生成API密钥:

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();
  }

在日志中查找KeyHash:

这是对Analizer代码的修改。