私のAndroid Appで私はAndroidスタジオの手順(追加 - >新しい活動 - > Google - >地図)で地図アクティビティを追加しました。私はこの例に従っています:https://developers.google.com/maps/documentation/android-api/start#step_2_install_the_google_play_services_sdk。Android:地図表示が機能しない
地図のアクティビティを開くと、奇妙なことに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>
ログを確認すると、APIキーに関するエラーが発生します。 –
ちょうどいつか起動するかもしれないが、それはプレイストアのアップデートをダウンロードしている可能性があります –