Google マップに問題があります。初めてアプリケーションを実行すると、マップは正常に表示されますが、閉じて再度実行すると、マップの画面が黒くなります。何が起こるかわかりませんが、アプリケーションのすべてのデータを消去すると、マップが再び表示されます。
初めて:
2回目(アプリケーションを閉じて再度実行したとき)
私はandroidx86プロジェクトで仮想ボックスを使用しています
手伝って頂けますか?
マップを設定した私のコード:
private void setUpMapIfNeeded() {
if (map == null) {
map = ((SupportMapFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
}
if (map != null) {
try{
map.setMyLocationEnabled(true);
map.setOnMyLocationButtonClickListener(this);
map.setOnMapLongClickListener(this);
map.setOnMarkerClickListener(this);
map.setOnMapClickListener(this);
map.setOnCameraChangeListener(this);
LocationManager locationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
String provider = locationManager.getBestProvider(criteria, true);
Location location = locationManager.getLastKnownLocation(provider);
if(location!=null){
double latitude = location.getLatitude();
double longitude = location.getLongitude();
LatLng latLng = new LatLng(latitude, longitude);
//ThreadMostraImoveisJson(latLng);
onLocationChanged(location);
}
}
catch (Exception ex){
Log.e("Erro Mapa", "Erro Setar Mapa: "+ex.getMessage());
}
}
}
私のXML:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mapHost"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</fragment>
<LinearLayout
android:id="@+id/layPesquisa"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#f4f4f4"
android:orientation="horizontal"
android:layout_gravity="right">
<Button
android:id="@+id/btnPesquisa"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="OK" />
<EditText
android:id="@+id/edtPesquisa"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="invisible"
android:text=""
/>
</LinearLayout>
</FrameLayout>