-2

我已经尝试了其他人的建议,但没有运气。我已经多次更改 API 密钥。

这是我的 MapActivity.java 的代码

package com.santehfeedsgis;

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

public class MapActivity extends FragmentActivity {

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

}

对于我的布局 activity_map.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"
tools:context=".MainActivity" >

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    />
<fragment
    android:id="@+id/map"
    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.santehfeedsgis"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="12"
    android:targetSdkVersion="17" />

<permission 
    android:name="com.santehfeedsgis.permission.MAPS_RECEIVE" 
    android:protectionLevel="signature"></permission>
<uses-permission 
    android:name="com.santehfeedsgis.permission.MAPS_RECEIVE"/>
<uses-permission 
    android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission 
    android:name="android.permission.INTERNET"/>
<uses-permission 
    android:name="android.permission.ACCESS_NETWORK_STATE"/>    
<uses-permission 
    android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission 
    android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission 
    android:name="android.permission.ACCESS_FINE_LOCATION"/>

<uses-feature
    android:glEsVersion="0x00020000"
    android:required="true"/>


<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >

    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="mysecretkeyhere/>

    <activity
        android:name="com.santehfeedsgis.MapActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

4

3 回答 3

1

你的 min sdk 是 12。扩展标准Activity。您可以使用MapFragment

   <fragment 
      android:id="@+id/map"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:name="com.google.android.gms.maps.MapFragment"/> 

还要确保您已在 google api 控制台中为 andorid 启用地图,并确保您已按照以下链接中的所有步骤操作

https://developers.google.com/maps/documentation/android/start

如果您的 min sdk 为 11 及以下,您需要使用SupportMapFragment在这种情况下您需要扩展FragmentActivtiy.

https://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/MapFragment

于 2013-08-04T17:29:21.453 回答
0

我想这会对你有所帮助。此链接适用于 Google Map with-in Fragments

https://developers.google.com/maps/documentation/android/map?hl=pl#using_xml_attributes

祝你好运。

于 2013-08-04T17:21:49.137 回答
0

哦,我终于通过转到 Eclipse WINDOW>Preferences>Android>Build 找到了答案,并使用了那里生成的 SHA1。:D

于 2013-08-04T17:57:04.353 回答