我的 GoogleMap 应用程序不会 运行,但 logcat 中没有错误

My GoogleMap application will not run and but no errors in logcat

我尝试创建一个基本的 Google 地图,但我 运行 这段代码不会 运行 在我的 phone 中。 ...我在 logcat 中也看不到 运行ning 进程错误,我更改了扩展 class SupportFragmentActivityMapFragmentActivityActivity 都没有用不行吗?

MainAcitivity

 public class MainActivity extends FragmentActivity {
       @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    }    }

清单文件

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="googlemap.com"
    android:versionCode="1"
    android:versionName="1.0" >
<uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="21" />
    <permission 
        android:name="google.com.permision.MAPS_RECEIVE"
        android:protectionLevel="signature"/>
    <uses-permission android:name="google.com.permission.MAPS_RECEIVE"/>
    <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 
            />
        <meta-data
    android:name="com.google.android.maps.v2.API_KEY"
    android:value="AIzaSyDBrdz7HdE74prr0mmtGtl4nIQq8C9wBD4"/>
        <meta-data 
    android:name="com.google.android.gms.version"
    android:value="@integer/google_play_services_version"/>
        <activity
            android:name=".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>
    </application>
</manifest>

主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" >
   <fragment
            android:id="@+id/map"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:name="com.google.android.gms.maps.SupportMapFragment"/>
    </RelativeLayout>

您是否在 phone 上检索到灰色地图?如果是这样,您的地图 API_KEY 设置不正确。

请尝试按照this一步步进行,您最终会在phone上得到一张地图。

我看到你的MainAcitivity里面什么都没有,示例代码:

public class MainActivity extends Activity {

    private static LatLng goodLatLng = new LatLng(37, -120);
    private GoogleMap googleMap;
    private EditText et_address, et_finalAddress;
    LatLng addressPos, finalAddressPos;
    Marker addressMarker;

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

        et_address = (EditText) findViewById(R.id.addressEditText);
        et_finalAddress = (EditText) findViewById(R.id.finalAddressEditText);


        // Initial Map
        try {

            if (googleMap == null) {
                googleMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        googleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
        // Put a dot on my current location
        googleMap.setMyLocationEnabled(true);
        googleMap.setIndoorEnabled(true);
        googleMap.setTrafficEnabled(true);
        // 3D building
        googleMap.setBuildingsEnabled(true);
        // Get zoom button
        googleMap.getUiSettings().setZoomControlsEnabled(true);

        Marker marker = googleMap.addMarker(new MarkerOptions()
                .position(goodLatLng)
                .title("Hello"));
    }

更多详情请参考我的githubhere.

你的XML

 <?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/iqamah_map"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:name="com.google.android.gms.maps.SupportMapFragment" />

你的JavaClass

 public class YourActivity extends FragmentActivity {

   GoogleMap map;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.your_activity);
        map =((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.iqamah_map)).getMap();

    }
}