I have a ViewPager that loads a MapFragment. In this case, the map is not visible, but the background changes to gray, i.e. you can clearly understand that the fragment MapFragment was attached without problems, but for some reason the map is not visible on the screen.

How to fix it?

My fragment_map.xml

<com.google.android.gms.maps.MapView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/map_view" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginTop="?attr/actionBarSize" android:layout_marginBottom="?attr/actionBarSize" /> 

My MapFragment.java

 public class MapFragment extends Fragment implements OnMapReadyCallback { private static final String MAP_FRAGMENT_LOG_TAG = "map_fragment_log"; private MapView mMapView = null; private GoogleMap mGoogleMap = null; public static MapFragment newInstance() { Bundle args = new Bundle(); MapFragment fragment = new MapFragment(); fragment.setArguments(args); return fragment; } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); MapsInitializer.initialize(MapFragment.this.getActivity().getBaseContext()); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); View v = inflater.inflate(R.layout.fragment_map, container, false); mMapView = (MapView) v.findViewById(R.id.map_view); mMapView.onCreate(savedInstanceState); mMapView.getMapAsync(this); return v; } @Override public void onResume() { super.onResume(); mMapView.onResume(); } @Override public void onMapReady(GoogleMap googleMap) { mGoogleMap = googleMap; mGoogleMap.addMarker(new MarkerOptions() .position(new LatLng(0, 0)) .title("Marker") .draggable(true) ); } @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); mMapView.onSaveInstanceState(outState); } @Override public void onPause() { super.onPause(); mMapView.onPause(); } @Override public void onDestroy() { super.onDestroy(); mMapView.onDestroy(); } @Override public void onLowMemory() { super.onLowMemory(); mMapView.onLowMemory(); } } 

My AndroidManifest.xml

 <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="стерто" > <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="com.arshad.map.permission.MAPS_RECEIVE" /> <permission android:name="com.arshad.map.permission.MAPS_RECEIVE" android:protectionLevel="signature" /> <uses-feature android:glEsVersion="0x00020000" android:required="true" /> <application android:name=".Application" android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme" > <activity android:name=".activities.MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".activities.LoginActivity" /> <meta-data android:name="io.fabric.ApiKey" android:value="стерто" /> <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /> <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="стерто" /> </application> </manifest> 
  • onMapReady is called? - Yura Ivanov
  • @YuraIvanov Checked. Called. - Alexander Lomovskiy
  • And in logcat'e nothing? Possible problems with the key ... It is worth trying to re-generate the key. blog-emildesign.rhcloud.com/?p=403 - Yura Ivanov
  • @YuraIvanov Thank you very much for your prompt assistance. Problem solved. I used the SHA1 release key, and the application is signed by a debug key, which was not there. I never would have thought that way. Thanks again. - Alexander Lomovskiy
  • @AlexanderLomovskiy, write how they solved the problem in the answer - it can help future questioners in a similar problem) - Juriy Spb

1 answer 1

According to the TC message in the comment, the problem was in the absence of the SHA-1 debazhny key, which signed the application