谷歌地图V2问题,没有显示

时间:2014-06-10 10:31:59

标签: android google-maps

我试图在我的应用程序中加载谷歌地图V2,但没有显示任何东西,只显示缩放的加号和减号。MapFragmentSupportMapFragment之间的差异。 片段:

<fragment
            android:id="@+id/map_full"
            class="com.google.android.gms.maps.MapFragment"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />

代码:

map = ((MapFragment) getFragmentManager().findFragmentById(
                R.id.map_full)).getMap();
        map.setMapType(GoogleMap.MAP_TYPE_NORMAL);

        Marker hamburg = map.addMarker(new MarkerOptions().position(HAMBURG)
                .title("Hamburg"));
        Marker kiel = map.addMarker(new MarkerOptions()
                .position(KIEL)
                .title("Kiel")
                .snippet("Kiel is cool")
                .icon(BitmapDescriptorFactory
                        .fromResource(R.drawable.face)));

        // Move the camera instantly to hamburg with a zoom of 15.
        map.moveCamera(CameraUpdateFactory.newLatLngZoom(HAMBURG, 15));

        // Zoom in, animating the camera.
        map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);

清单:

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

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


    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />
<permission
    android:name="com.example.ylp.permission.MAPS_RECEIVE"
    android:protectionLevel="signature" />

<uses-permission android:name="com.example.ylp.permission.MAPS_RECEIVE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />
    <!-- Required to show current location -->
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.RECEIVE_SMS" >
    </uses-permission>
    <uses-permission android:name="android.permission.CALL_PHONE" />
    <uses-permission android:name="android.permission.READ_SMS" />
    <uses-permission android:name="android.permission.SEND_SMS" >
    </uses-permission>
    <uses-permission android:name="android.permission.WRITE_SETTINGS" />
    <uses-permission android:name="android.permission.RECEIVE_SMS" >
    </uses-permission>

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.ylp.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>
        <activity android:name="com.example.ylp.JobDetail" />
        <activity android:name="com.example.ylp.AddJob" />
        <activity android:name="com.example.ylp.ListJob" />
        <activity android:name="com.example.ylp.GetAddress" />
        <activity android:name="com.example.ylp.SignUp" />
        <activity android:name="com.example.ylp.AddReview" />
        <activity android:name="com.example.ylp.NearBy" />
        <activity android:name="com.example.ylp.AboutMe" />
        <activity android:name="com.example.ylp.Map" />
        <activity android:name="com.example.ylp.FullMap" />

        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />
        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="AIzaSyC87SwLmEWUm06kpqK8lj0UugBrcgDwDK4" />
    </application>

</manifest>

1 个答案:

答案 0 :(得分:1)

如果 android:minSdkVersion&gt;“12”那么您需要使用

<fragment
        android:id="@+id/map_full"
        class="com.google.android.gms.maps.MapFragment"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />

您的活动必须扩展 Activity

并使用

获取Map
map = ((MapFragment) getFragmentManager().findFragmentById(
            R.id.map_full)).getMap();

如果您的 android:minSdkVersion&lt;“12”那么您需要使用

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

您的活动必须扩展 FragmentActivity

并使用

获取Map
map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(
            R.id.map_full)).getMap();

并且对于您的问题,您需要检查API Key