我與show map
有問題,但是爲什麼要顯示empty map
?!像圖像空映射當在android studio中運行代碼
我給你介紹我的代碼 我把關鍵文件release/res/values/google_map_api.xml
,也把在debug/res/values/google_map_api.xml
<resources>
<string name="google_maps_key" translatable="false" templateMergeStrategy="preserve">
AIzaSyDci-------------hSik
</string>
</resources>
我也把我的鑰匙androidManifest.xml
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyDci-------------hSik" />
和MapActivity.java
的代碼
public class MapsActivity extends AppCompatActivity implements OnMapReadyCallback {
private GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// 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);
}
@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));
}
}
注意:使用手機Galaxy Note
不是emulator
android studio。
你可以添加的logcat和'activity_maps'佈局文件? – Hein
嘗試使用'MagFragment'而不是'SupportMapFragment' –
我不明白如何添加logcat? – SaharSafran