在谷歌地图v2中我只显示黑屏。解决此问题

时间:2013-12-21 08:27:43

标签: android

如何解决。我在真实设备上检查此代码,但没有显示map.just白色屏幕我提前show.thanks。请告诉我锄头来解决这个问题。 enter image description here

androidmanifest.xml ##标题##

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

        <uses-sdk
            android:minSdkVersion="8"
            android:targetSdkVersion="19" />


        <uses-permission android:name="android.permission.INTERNET"/>
        <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
        <uses-permission android:name="android.permission.READ_PHONE_STATE" />
        <uses-permission android:name="com.example.main.permission.MAPS_RECEIVE" />
        <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
        <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
        <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
        <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
        <uses-permission android:name="android.permission.SEND_SMS"/>
        <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
        <uses-permission android:name="android.permission.RECEIVE_SMS" />

        <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" >
            <activity
                android:name="com.example.main.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=".DriverSelectedRoute"></activity>
            <activity android:name=".ShowRouteMap"></activity>
            <activity android:name=".StudentCheckBoxAndListShow"></activity>

             <meta-data
                android:name="com.google.android.gms.version"
                android:value="4030500" />

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

        </application>

    </manifest>

ShowRouteMap.xml ##标题##

package com.example.main;

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;


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

public class ShowRouteMap extends FragmentActivity
{

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

        SupportMapFragment mapFragment = ((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map));
        GoogleMap mMap = mapFragment.getMap();
        Log.d("google map class...", "google map");
        mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);

    /*  SupportMapFragment mapFragment1 = ((SupportMapFragment) this
                .getSupportFragmentManager().findFragmentById(R.id.map));*/
    }

}

show_route_map.xml ##标题##

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TextView
        android:id="@+id/routeNameShowTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_marginRight="34dp"
        android:layout_marginTop="18dp"
        android:hint="@string/route_name_show_text_view"
        android:textSize="20sp" />

    <TextView
        android:id="@+id/routeNameTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/routeNameShowTextView"
        android:layout_alignBottom="@+id/routeNameShowTextView"
        android:layout_alignParentLeft="true"
        android:layout_marginLeft="18dp"
        android:text="@string/route_name_text_view"
        android:textSize="20sp" />

    <TextView
        android:id="@+id/totalDistanceTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/routeNameTextView"
        android:layout_marginTop="16dp"
        android:text="@string/total_distance_text_view"
        android:textSize="20sp" />

    <TextView
        android:id="@+id/totalDistanceShowTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/totalDistanceTextView"
        android:layout_alignLeft="@+id/routeNameShowTextView"
        android:hint="@string/total_distance_show_text_view"
        android:textSize="18sp" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_marginBottom="23dp"
        android:text="@string/check_student_button"
        android:textSize="15sp" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignTop="@+id/button1"
        android:text="@string/student_view_show_button"
        android:textSize="15sp" />

    <fragment
        android:id="@+id/map"
        android:layout_width="1300sp"
        android:layout_height="300sp"
        android:layout_above="@+id/button1"
        android:layout_alignParentLeft="true"
        class="com.google.android.gms.maps.SupportMapFragment" />

</RelativeLayout>

1 个答案:

答案 0 :(得分:0)

首先,永远不要在模拟器中检查您的Google Map API V2应用程序。总是尝试使用真实的设备。

现在为您解决问题,因为它看起来您在Manifest文件中缺少权限:

<permission android:name="com.example.main.permission.MAPS_RECEIVE" android:protectionLevel="signature"/>

如果添加此功能无效,请尝试使用API​​控制台重新创建API密钥。查看 本指南旨在确保您正确执行所有步骤:

Google Maps API V2 Key