2017-05-03 34 views
0

當在API級別大於23的應用程序中構建應用程序時,Google地圖不會顯示在棉花糖設備中,但它在棉花糖版本下正確顯示。我使用過MapView。谷歌地圖不可見在android棉花糖?

Actally我在棉花糖,這就是爲什麼我在marshmallow.For獲取當前緯度郎我使用該行面臨的問題越來越當前LAT郎(0,0): -

私人無效getCurrentLatLong(){

第一
try { 
     gps = new GPSTracker(getActivity()); 

     if (gps.canGetLocation()) { 

      double latitude = gps.getLatitude(); 
      double longitude = gps.getLongitude(); 

      System.out.println("latitude print==" + latitude); 


      lat = String.valueOf(latitude); 
      lng = String.valueOf(longitude); 
      System.out.println("lat long check====" + "lati :" + lat + " -- lng :" + lng); 

      if (lat.equalsIgnoreCase("0.0") || lng.equalsIgnoreCase("0.0")) { 
       getCurrentLatLong(); 
      } else { 
       mMapView.onResume(); 
       setMap(); 
      } 

     } else { 
      // can't get location 
      // GPS or Network is not enabled 
      // Ask user to enable GPS/network in settings 
      gps.showSettingsAlert(); 
     } 
    } catch (Exception ex) { 
     ex.printStackTrace(); 
    } 

} 
+0

你介意顯示你的代碼嗎? –

+0

如果發生錯誤,則顯示代碼以及錯誤logcat –

+0

@Luiz Fernando Salvaterra實際上,當我在23以上構建應用程序時,我沒有獲得當前經緯度總是(0,0)棉花糖設備但低於棉花糖其工作正常 –

回答

1

第一這個權限必須

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 
<uses-permission android:name="android.permission.INTERNET" /> 

然後,當你想使用的位置圖

if (ContextCompat.checkSelfPermission(Maps_Activity.this,Manifest.permission.ACCESS_FINE_LOCATION) 
      != PackageManager.PERMISSION_GRANTED) { 

    // Should we show an explanation? 
    if (ActivityCompat.shouldShowRequestPermissionRationale(Maps_Activity.this, Manifest.permission.ACCESS_FINE_LOCATION)) { 

    } else { 

     // No explanation needed, we can request the permission. 

     ActivityCompat.requestPermissions(Maps_Activity.this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION},PERMISSION_REQUEST_CODE); 
    } 
} 
else{ 
    //load your map here 
} 

而且overrride onRequestPermissionsResult需要運行許可。

@Override 
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) { 
    switch (requestCode) { 
     case PERMISSION_REQUEST_CODE: { 
      // If request is cancelled, the result arrays are empty. 
      if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { 

       // permission was granted, yay! 
       // load your map here also 

      } else { 

       // permission denied, boo! Disable the 
       // functionality that depends on this permission. 
      } 
      return; 
     } 

     // other 'case' lines to check for other 
     // permissions this app might request 
    } 
} 
0

格蘭特的應用權限,設置 - >您的應用程序 - >權限 - >啓用需要許可

+0

並且編寫代碼以在運行時加載映射之前啓用權限或請求權限,以避免問題 –

+0

我已經完成了所有這些工作,但仍然面臨此問題。 –