2016-03-16 123 views
0
  • 我想表明谷歌地圖加載過程中進度條進度對話框不顯示

  • 進度條,直到谷歌地圖專注於我的當前位置

  • 我想顯示進度對話框像下面圖像

enter image description here

代碼:

- 相機着眼當前位置

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)); 
+0

我猜ü有網絡和GPS檢查後,您使用的不是最好的標準LocationManager.NetworkProvider試圖找到當前的位置.. ..之前Becoz大多數時候,標準給出了GPS。它不是一個好的選擇..也有一個progressBar並把這行代碼** mProgressBar.setIndeterminate(true); **和可見性在調用getMapReady中的位置之前可見並且一旦位置不爲null使得可見性GONE ..這應該有助於 – DJphy

+0

,但如何顯示進度欄,直到地圖被淹沒? – Risk

+0

首先,當您可以使用FusedLocationApi時,請勿使用自己的位置管理器。該API在連接時具有回調,並且可以獲取最新的緯度/經度座標。 Google mapView具有回調功能,可以在地圖準備就緒並加載時通知您。 – TheSunny

回答

3

在XML其中u有烏爾圖;宣佈一個進度條,像這樣; intially其知名度將會消失(意味着它會被隱藏):

<ProgressBar 
    android:id="@+id/progressBar" 
    style="?android:attr/progressBarStyleSmall" 
    android:layout_width="60dp" 
    android:layout_height="60dp" 
    android:layout_centerHorizontal="true" 
    android:layout_marginTop="45dp" 
    android:padding="5dp" 
    android:visibility="gone" /> 

然後初始化烏爾進度在烏爾顯示烏爾地圖的活動;聲明爲一個類變量:

mProgressBar = (ProgressBar) findViewById(R.id.progressBar); 
mProgressBar.setIndeterminate(true); 

然後在烏爾地圖活動的OnCreate設定進度的可見能見度:

mProgressBar.setVisibility(View.VISIBLE); 

然後在地方UR調用gmap.AnimateCamera(即當你縮放)其中位置不爲空if子句; U中的可見性設置爲不見了:

mProgressBar.setVisibility(View.GONE); 

享受

+0

抱歉可以幫助我多一次。我想設置進度條的背景透明..即只有圓應該是可見的 – Risk

+0

我的互聯網似乎並沒有工作..我會回覆一次,如果它的trobleshooted – DJphy

+0

我已經做到了..謝謝你 – Risk