1

我有一个地图程序,当我在模拟器中运行它时运行良好,但是当我在手机上运行它时是白屏,为什么?也许我错了?

这是代码:

    package com.example.pi;


import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

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

public class maps extends FragmentActivity
{
private GoogleMap map;

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

private void setupMap()
{
if (map == null)
{
map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.maps)).getMap();
if (map != null)
{
map.addMarker(new MarkerOptions().position(new LatLng(-7.795581, 110.376999)).title("Museum Batik Yogyakarta").snippet("Jl. Dr Sutomo 13 A RT 049 RW 12 Bausasran Danurejan Yogyakarta DIY"));
map.addMarker(new MarkerOptions().position(new LatLng(-8.504684, 115.25406)).title("The Blanco Renaissance Museum").snippet("Jalan Campuhan, Ubud"));
map.addMarker(new MarkerOptions().position(new LatLng(-6.176129, 106.822407)).title("Museum Nasional Indonesia").snippet("Jl. Medan Merdeka Barat 12, 10110, Indonesia"));
map.addMarker(new MarkerOptions().position(new LatLng(-6.9204314, 107.609893)).title("Museum Asia Afrika").snippet("Asia Afrika 65, Bandung 40111"));
map.addMarker(new MarkerOptions().position(new LatLng(-7.264724, 110.402201)).title("Museum Kereta Api Ambarawa").snippet("Jalan Stasiun 1, Ambarawa"));
map.addMarker(new MarkerOptions().position(new LatLng(-7.972623, 112.61953)).title("Museum Brawijaya").snippet("Jalan Ijen 25 A, Malang"));
map.addMarker(new MarkerOptions().position(new LatLng(-0.411769, 116.990318)).title("Museum Negeri Provinsi Kalimantan Timur Mulawarman").snippet("Jalan Diponegoro 26 Tenggarong Kelurahan Panji Kecamatan Tenggarong, Kutai Kartanegara"));
map.addMarker(new MarkerOptions().position(new LatLng(-8.591757, 116.085105)).title("Museum Negeri Propinsi Nusa Tenggara Barat").snippet("Jalan Panji Tilar Negara 6,  Mataram"));
map.addMarker(new MarkerOptions().position(new LatLng(-10.159336, 123.619366)).title("Museum Negeri Propinsi Nusa Tenggara Timur").snippet("Jalan El Tari  II Kota Baru, Kupang"));
map.addMarker(new MarkerOptions().position(new LatLng(-2.594777, 140.630955)).title("Museum Negeri Propinsi Papua").snippet("Jalan Raya Sentani Km 17.8 Wamena Kecamatan Abepura, Jayapura"));
map.addMarker(new MarkerOptions().position(new LatLng(-5.134677, 119.408587)).title("Museum Kota Makassar").snippet("Jalan Balai Kota 11 A Kelurahan Baru Kecamatan Ujung Pandang, Makassar 90111"));
map.addMarker(new MarkerOptions().position(new LatLng(3.567996, 98.696365)).title("Museum Negeri Propinsi Sumatera Utara").snippet("Jalan H.M. Joni 51 Teladan Barat, Medan 20217"));
map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(-8.504684, 115.25406),3));
}
}

}

}

这是清单:

*<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.pi"
    android:versionCode="1"
    android:versionName="1.0" >
    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

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

    <uses-permission android:name="com.example.pi.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.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
    <uses-permission android:name="com.example.pi.addtask.permission.MAPS_RECEIVE"/>
    <uses-permission android:name="com.example.pi.permission.C2D_MESSAGE" />
     <uses-permission android:name="android.permission.ACCESS_COARSE_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" >
    <!-- Google Maps API V2 -->
        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="AIzaSyAyshvLXf6xnb48vST1pkjaT3Cbp-z5Xfs" />
        <activity
            android:name="com.example.pi.maps"
            android:label="@string/app_name" ></activity>    

        <activity
            android:name=".splash"
            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="Main"></activity>
        <activity android:name=".bantuan"></activity>
        <activity android:name=".tentang"></activity>
        <activity android:name=".provinsi"></activity>
        <activity android:name=".bali"></activity>
        <activity android:name=".theblanco"></activity>
        <activity android:name=".jabar"></activity>
        <activity android:name=".kaa"></activity>
        <activity android:name=".ntb"></activity>
        <activity android:name=".mus_ntb"></activity>
        <activity android:name=".ntt"></activity>
        <activity android:name=".mus_ntt"></activity>
        <activity android:name=".yogya"></activity>
        <activity android:name=".mon_yogya"></activity>
        <activity android:name=".batik_yogya"></activity>
        <activity android:name=".jateng"></activity>
        <activity android:name=".mus_ambarawa"></activity>
        <activity android:name=".jatim"></activity>
        <activity android:name=".mus_brawijaya"></activity>
        <activity android:name=".jakarta"></activity>
        <activity android:name=".mus_nasional"></activity>
        <activity android:name=".kalimantan"></activity>
        <activity android:name=".mus_kaltim"></activity>
        <activity android:name=".papua"></activity>
        <activity android:name=".mus_papua"></activity>
        <activity android:name=".sulawesi"></activity>
        <activity android:name=".mus_makassar"></activity>
        <activity android:name=".sumatera"></activity>
        <activity android:name=".mus_sumut"></activity>

    </application>



</manifest>*

抱歉我的英语不好:D

4

1 回答 1

1

您应该首先打开 LogCat 并检查发生了什么,但通常一个空地图意味着您没有有效的 Google Maps API 密钥,或者您没有在 Google 的调试权限中包含您的计算机 SHA-1 代码API 控制台。

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

于 2013-05-24T18:24:24.637 回答