Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MapView shows empty tiles in GoogleMaps API v2 for Android

I'm moving my app to the new Google's API for Android. I've decided to use the MapView and not the Fragment since the map is a part of a Fragment. I've succeeded to show a map with the MapFragment, but when trying to do the same with the MapView it just shows empty tiles. Does anyone has a clew what I'm missing? These are the permissions from the Manifest file:

<permission android:name="com.beezer.permission.MAPS_RECEIVE" 
                 android:protectionLevel="signature"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="com.beezer.permission.MAPS_RECEIVE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

I don't get any error in the log.

like image 343
user1240792 Avatar asked Dec 05 '22 13:12

user1240792


2 Answers

Have you forwarded all the Activity life cycle methods as written here https://developers.google.com/maps/documentation/android/map#mapview

"Users of this class must forward all the Activity life cycle methods - such as onCreate(), onDestroy(), onResume(), and onPause() - to the corresponding methods in the MapView class."

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    mapView.onCreate(savedInstanceState);
    try {
       MapsInitializer.initialize(mContext);
    } catch (GooglePlayServicesNotAvailableException e) {
       e.printStackTrace();
    }
 }

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

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

@Override
public void onDestroy() {
    super.onDestroy();
    mapView.onDestroy();
}
like image 95
Romain Dereum Avatar answered Feb 24 '23 14:02

Romain Dereum


There are only two issues I can this of :

  1. The signatures of your build do not match with your maps api key
  2. You are not using MapView from inside a MapActivity. It will not work otherwise.
like image 37
StarNix Avatar answered Feb 24 '23 16:02

StarNix