8

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

在此处输入图像描述

主要的.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

4 回答 4

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

 }

 }
于 2013-04-12T07:10:09.137 回答
0

如果您尝试了 sdk extras 中的地图示例,您可能会发现此答案很有帮助。

于 2013-10-17T20:26:06.867 回答
0

还有用于android密钥生成的名称包问题的概率

于 2014-04-14T08:48:48.653 回答
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:。

这是对分析器代码的修改。

于 2014-07-07T18:04:10.920 回答