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!