2013-07-18 20 views
23

Google Map Api v2(https://developers.google.com/maps/documentation/android/start#specify_settings_in_the_application_manifest)のGoogleマップドキュメントで提供されているサンプルコードを実行しています。Google Map API v2が表示されない

コードは正常に実行されましたが、マップはデバイスにロードされません。デバイスには白い画面のみが表示されます。私は4.0.3バージョンのAndroidデバイスを使用しています。

enter image description here

1)私はプロジェクトのためのサービスを可能にしました。プロジェクト内のライブラリとして

enter image description here

enter image description here

3) "グーグル・プレイservices_lib":

enter image description here

2)キーを生成

enter image description here

4)アンドロイドマニフェスト:

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

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

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

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

    <uses-permission android:name="com.example.mapdemo.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="com.google.android.providers.gsf.permission.READ_GSERVICES" /> 
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> 
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 

    <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="AIzaSyCvZrhQ8YBfyYBvTic3DSdu2O06nAmhpg4" /> 

     <activity 
      android:name="com.example.mapdemo.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> 

5)活性:

package com.example.mapdemo; 

import android.app.Activity; 
import android.os.Bundle; 
import android.view.Menu; 

public class MainActivity extends Activity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main);  
    } 
    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 

     getMenuInflater().inflate(R.menu.main, menu); 
     return true; 
    } 
} 

6)レイアウト:

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

また、私はこれで混乱していた、それは私がAPIコンソールに入力したパッケージ名が完全ではなかった初めてです。その後、マップを再インストールしてもまだ表示されませんでした。しかし、私はちょっと待たなければなりませんでした。 – Ixx

+0

ちょうど好奇心から - あなたはどのようにアクセス許可を把握しましたか?私はGoogleのドキュメントを読んだだけで、あなたはインターネット、ACCESS_NETWORK_STATE、WRITE_EXTERNAL_STORAGEの権限と、オプションでACCESS_COARSE_LOCATIONとACCESS_FINE_LOCATIONの権限が必要だと言っていました。だから、MAPS_RECEIVEとREAD_GSERVICESはどこから来たのですか? – Chris

答えて

15

使用フラグメントの活性

例えば:

public class Maps extends FragmentActivity { 
    GoogleMap map; 
    double lat; 
    double lan; 
    boolean flag = false; 

    // private LocationManager lm; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.mapptry); 

     map = ((SupportMapFragment) getSupportFragmentManager() 
       .findFragmentById(R.id.map)).getMap(); 
       } 
    } 

変更

このも

輸入android.support.v4.app.FragmentActivityを行うようになった

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

EDITにウルmap.xml。

あなたはこの右クリック操作を行う前に、プロジェクト - >プロパティ - > buildpath-> Javaのビルド・パスが - >ライブラリ..その後、

ユーザー\ android-に行く外部のjarファイル

を追加をクリックSDK \エクストラ\アンドロイド\サポート\ v4の

アンドロイド・サポート・v4.jarを選択

PS:このすべてはあなたを提供しますr APIキーが正しい。キーが間違っているあなたAPIは、その後も、それだけで白い画面が表示されている場合

+0

質問を投稿するときに行ったのと同じようにAPIキーを公開しないでください。ここではうまくいきません。 – larrytech

+0

私のAPIキーが無効で、キーを再生成して機能しました。 – ashishdhiman2007

3

を使用すると、アプリケーションの外部次のコードを追加した

GoogleMap googleMap = ((MapFragment)getFragmentManager().findFragmentById(R.id.map)).getMap(); 

を追加し、

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

であなたのxmlを交換してみてくださいタグの代わりにタグ

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

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

これは同じ問題に直面している誰かを助けるかもしれないことを願っています

1

APIキーでこの問題があるかもしれません。プロジェクトのapiコンソール(https://console.developers.google.com/project)とEclipse - > Preferences - > Android - >ビルドは同じですが、他の方法ではSHA1をコンソールからパスを構築するように更新するか、あるいはその逆にします。

0

あなたが言及したもの、以下のことを確認したときにおそらくあなたの問題が解決されます:APIキーを生成しながら

  1. は、私の場合には、これはした(GoogleマップAPIに

  2. 使用正しいパッケージ名を有効にしますパッケージ名が間違っているようです(com.example.mapdemo)これはあなたの場合にも問題に見えます

  3. SHA1を生成するための正しいキーストアファイル

希望します。

0

システムとユーザーのセキュリティを維持するために、Androidはアプリケーションが特定のシステムデータと機能を使用する前に許可を要求する必要があります。どの程度敏感であるかに応じて、システムは自動的に許可を与えるか、ユーザーに要求の承認を求めることがあります。

https://developer.android.com/guide/topics/permissions/index.html

関連する問題