我想表明谷歌地圖加載過程中進度條進度對話框不顯示
進度條,直到谷歌地圖專注於我的當前位置
我想顯示進度對話框像下面圖像
代碼:
- 相機着眼當前位置
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
if (ActivityCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
Location location = locationManager.getLastKnownLocation(locationManager.getBestProvider(criteria, false));
if (location != null)
{
googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(
new LatLng(location.getLatitude(), location.getLongitude()), 19));
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(new LatLng(location.getLatitude(), location.getLongitude())) // Sets the center of the map to location user
.zoom(19) // Sets the zoom
.bearing(90) // Sets the orientation of the camera to east
// Sets the tilt of the camera to 30 degrees
.build(); // Creates a CameraPosition from the builder
googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
我猜ü有網絡和GPS檢查後,您使用的不是最好的標準LocationManager.NetworkProvider試圖找到當前的位置.. ..之前Becoz大多數時候,標準給出了GPS。它不是一個好的選擇..也有一個progressBar並把這行代碼** mProgressBar.setIndeterminate(true); **和可見性在調用getMapReady中的位置之前可見並且一旦位置不爲null使得可見性GONE ..這應該有助於 – DJphy
,但如何顯示進度欄,直到地圖被淹沒? – Risk
首先,當您可以使用FusedLocationApi時,請勿使用自己的位置管理器。該API在連接時具有回調,並且可以獲取最新的緯度/經度座標。 Google mapView具有回調功能,可以在地圖準備就緒並加載時通知您。 – TheSunny