0

I'm currently working to improve an existing android app that maps different types of trees in an area.

When the app is downloaded from the Google Play Store, the maps works fine. However when I'm working on it in Android Studios, it simply shows a grey screen.

I got an API key from google and put it in google_maps_api.xml

This is how I'm initializing the map:

if (savedInstanceState != null) {
        mMapFragment = (MapFragment) myFragmentManager.findFragmentByTag("map_tag");

        mMapFragment.getMapAsync(new OnMapReadyCallback() {
            @Override
            public void onMapReady(GoogleMap googleMap) {
                mMap = googleMap;

                setUpMap();
            }
        });
        myFragment = (ControlClass) myFragmentManager.findFragmentByTag("control_tag");
        fragmentTransaction.commit();
        //mMap=mMapFragment.getMap();

    } else {

        mMapFragment = MapFragment.newInstance();
        fragmentTransaction.add(R.id.map, mMapFragment, "map_tag");

        useGPS = true;

        mMapFragment.setRetainInstance(true);
        myFragment = new ControlClass();
        fragmentTransaction.add(R.id.myfragment, myFragment, "control_tag");
        fragmentTransaction.commit();

        mMapFragment.getMapAsync(new OnMapReadyCallback() {
            @Override
            public void onMapReady(GoogleMap googleMap) {
                mMap = googleMap;

                setUpMap();
                //handleNewLocation(lastKnownPosition);

            }
        });

    }

These are the permissions I'm using in my AndroidManifest:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<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" />

This is my layout for the maps activity:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:tools="http://schemas.android.com/tools"
          android:id="@+id/layout_root_view"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:orientation="vertical"
          tools:context=".MainActivity">

<LinearLayout
    android:id="@+id/myfragment"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"

    android:orientation="vertical"/>

<LinearLayout
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"

    android:orientation="vertical"/>

Any help would be greatly appreciated!

Community
  • 1
  • 1
Ngabo
  • 1
  • 2
  • Looks like you had the reverse problem of the question here: https://stackoverflow.com/questions/30559602/android-studio-google-map-still-blank-on-real-android-device – Daniel Nugent Aug 04 '17 at 20:01

1 Answers1

0

So as it turns out, there are two versions of google_maps_api.xml, and my manifest was referring to the debug version, which still contained the previous api key. Changing the key in the debug version of google_maps_api.xml fixed the problem.

Ngabo
  • 1
  • 2