Gaurav Bhagat
Gaurav Bhagat

Reputation: 97

MapView Map is not rendering on runtime {Screenshot Attached}

I am trying to add the MapView in the Fragment, my app was running well but unable to load the map details or geolocations. Please find the details in the mentioned screenshot. Google Codes work but not loading the maps in MapView. I have also mentioned the code below which I am trying to perform but getting the runtime issues.

enter image description here

NearbyFragment.java

public class NearbyFragment extends Fragment implements OnMapReadyCallback {

private MapView mMapView;

private static final String MAPVIEW_BUNDLE_KEY = "MapViewBundleKey";


View rootNearby;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    rootNearby = inflater.inflate(R.layout.fragment_nearby, container, false);
    // Inflate the layout for this fragment

    initGoogleMaps(savedInstanceState);

    return rootNearby;
}

private void initGoogleMaps(Bundle savedInstanceState) {
    Bundle mapViewBundle = null;
    if (savedInstanceState != null) {
        mapViewBundle = savedInstanceState.getBundle(MAPVIEW_BUNDLE_KEY);
    }
    mMapView = (MapView) rootNearby.findViewById(R.id.mapView_NearbyMap);
    mMapView.onCreate(mapViewBundle);

    mMapView.getMapAsync(this);

}

@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);

    Bundle mapViewBundle = outState.getBundle(MAPVIEW_BUNDLE_KEY);
    if (mapViewBundle == null) {
        mapViewBundle = new Bundle();
        outState.putBundle(MAPVIEW_BUNDLE_KEY, mapViewBundle);
    }

    mMapView.onSaveInstanceState(mapViewBundle);
}

@Override
public void onResume() {
    super.onResume();
    mMapView.onResume();
}

@Override
public void onStart() {
    super.onStart();
    mMapView.onStart();
}

@Override
public void onStop() {
    super.onStop();
    mMapView.onStop();
}

@Override
public void onMapReady(GoogleMap map) {
    map.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker"));

    if (ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION)
            != PackageManager.PERMISSION_GRANTED) {
        return;
    }
    map.setMyLocationEnabled(true);
}

@Override
public void onPause() {
    mMapView.onPause();
    super.onPause();
}

@Override
public void onDestroy() {
    mMapView.onDestroy();
    super.onDestroy();
}

@Override
public void onLowMemory() {
    super.onLowMemory();
    mMapView.onLowMemory();
}}

Upvotes: 1

Views: 110

Answers (1)

Transformer
Transformer

Reputation: 7439

Edit: Added a more comprehensive answer with all the possible issues to render/display map correctly with links and steps, there is a nice tutorial here too.. below are additional steps to troubleshoot.

Follow these steps:

  1. Verify the manifest AndroidManifest.xml, often this and the layout could be the problem for rendering a map. It could be called something like google_maps_api.xml

enter image description here

  1. In GoogleMaps for Android, you need both keys - debug and release.

    The "debug" key is used in other important places, its also used when you develop the app in Eclipse. The same debug key is used for development, testing, debugging.

    The debug key for signing your application can be found in the userhome/.android/debug.keystore file.

    To create the SHA-1 for your debug keystore you use the keytool command from your JDK installation.

    keytool -list -v -alias androiddebugkey \ -keystore <path_to_debug_keystore>debug.keystore \ -storepass android -keypass android

    enter image description here

  2. Prior to publishing app to Market, change the android:debuggable="false" in the AndroidManifest.xml and use your Signed API key here.

  3. Check to use the correct Fingerprint like #3 above keytool -list -keystore ~\.android\debug.keystore ...

  4. Then go to your user dir. on windows and clean this old file out to C:\Users\dev2.Tykt.org\.android and deleted debug.keystore and default.keysetTykt

  5. Lastly, after this, goto Eclipse run a clean build on your project and its done!

Upvotes: 1

Related Questions