Google 地图在 android 棉花糖中不可见?

Google Map in not Visible in android marshmallow?

Google 在 API 等级大于 23 时构建应用程序时地图未显示在 marshmallow 设备中,但它在 marshmallow 以下正确显示 version.I 使用了 MapView。

实际上我在 Marshmallow 中获取 Current lat lang (0,0) 这就是为什么我在 marshmallow.For 获取当前 lat lang 时遇到问题我正在使用此行:-

私人无效 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();
    }

}  

首先授予应用程序权限,设置 -> 您的应用程序 -> 权限 -> 启用需要权限

首先这个权限必须有

<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
}

以及覆盖 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
    }
}