2016-04-27 11 views
1

私のAndroid Appで私はAndroidスタジオの手順(追加 - >新しい活動 - > Google - >地図)で地図アクティビティを追加しました。私はこの例に従っています:https://developers.google.com/maps/documentation/android-api/start#step_2_install_the_google_play_services_sdkAndroid:地図表示が機能しない

地図のアクティビティを開くと、奇妙なことにGoogleのロゴが表示されているだけですが、完全に空白です(スクリーンショットを添付しています)。私は接続やキーのエラーメッセージが表示されません。どうして?

PSアクティビティJavaファイルに「import com.mycompany.myapp.R」行が追加されました。自動プロシージャで作成された元のファイルでは、そのファイルのすべての「R」がエラー。

要約:私は地図アクティビティを追加している

1)のAndroid Studioの自動手順 2を聖霊降臨祭)私は手順に従い、私のアプリでキーをコピーした(私は、任意のキーまたは証明書エラーが表示されませんメッセージ) 3)私はインポートcom.mycompany.myapp.Rについての行を追加するだけです 4)私は私の実際のデバイスでテストすると、空白のマップが表示されます。

ありがとうございました!活動の

コード:

package com.mycompany.myapp.Views; 
 

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

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

 
//I have added only this one! 
 
import com.mycompany.myapp.R; 
 

 
public class myFragmentMap extends FragmentActivity implements OnMapReadyCallback { 
 

 
    private GoogleMap mMap; 
 

 
    @Override 
 
    protected void onCreate(Bundle savedInstanceState) { 
 
     super.onCreate(savedInstanceState); 
 
     setContentView(R.layout.fragment_myapp_map); 
 
     // Obtain the SupportMapFragment and get notified when the map is ready to be used. 
 
     SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() 
 
       .findFragmentById(R.id.map); 
 
     mapFragment.getMapAsync(this); 
 
    } 
 

 

 
    /** 
 
    * Manipulates the map once available. 
 
    * This callback is triggered when the map is ready to be used. 
 
    * This is where we can add markers or lines, add listeners or move the camera. In this case, 
 
    * we just add a marker near Sydney, Australia. 
 
    * If Google Play services is not installed on the device, the user will be prompted to install 
 
    * it inside the SupportMapFragment. This method will only be triggered once the user has 
 
    * installed Google Play services and returned to the app. 
 
    */ 
 
    @Override 
 
    public void onMapReady(GoogleMap googleMap) { 
 
     mMap = googleMap; 
 

 
     // Add a marker in Sydney and move the camera 
 
     LatLng sydney = new LatLng(-34, 151); 
 
     mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney")); 
 
     mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney)); 
 
    } 
 
}

GoogleマップAP:活動に関連

コードのjavaファイルの

<fragment xmlns:android="http://schemas.android.com/apk/res/android" 
 
    xmlns:map="http://schemas.android.com/apk/res-auto" 
 
    xmlns:tools="http://schemas.android.com/tools" 
 
    android:id="@+id/map" 
 
    android:name="com.google.android.gms.maps.SupportMapFragment" 
 
    android:layout_width="match_parent" 
 
    android:layout_height="match_parent" 
 
    tools:context="com.mycompany.myapp.Views.myFragmentMap" />

<resources> 
 

 
    <string name="google_maps_key" templateMergeStrategy="preserve" translatable="false"> 
 
     AIza.... (and the correct code imported from Google) 
 
    </string> 
 
</resources>

そして、これは enter image description here

+0

ログを確認すると、APIキーに関するエラーが発生します。 –

+0

ちょうどいつか起動するかもしれないが、それはプレイストアのアップデートをダウンロードしている可能性があります –

答えて

0

活動の画面であるあなたは、右のGoogle Playのサービスをインストールした後、アプリケーションを実行しました:私は私のキーをコピーしている中で、ファイルSDK?

Danielが正しい場合は、APIキーに関連するエラーのログを確認できます。

Get a Google Maps API key

アプリケーションは、GoogleマップのサーバにアクセスするためのAPIキーを必要とします。必要な鍵の種類は、Androidアプリケーションの鍵です。鍵は無料です。 Google Maps Android APIを呼び出すアプリケーションで使用でき、無制限の数のユーザーをサポートします。

は、Android Studioが自動的に作成google_maps_api.xmlファイルで提供された資格情報を使用します。

  1. コピーgoogle_maps_api.xmlファイルで提供された資格情報を。
  2. お使いのブラウザのGoogle Developers Consoleにアクセスしてください。
  3. コピーした認証情報を使用して、アプリを既存のAPIキーに追加するか、新しいAPIキーを作成します。詳細は、complete processを参照してください。

1-7のすべての手順を実行すると、基本的な動作のGoogleマップアプリが表示されます。私はそれが助けて欲しいあなたの経験を関連付けるかもしれない前のGoogle Map on Android do not loadもここにあります。

関連する問題