1

I am using GoogleMap v2 API in my application. When I do a fresh install and I am connected to wifi, the Google map loads and displays fine in my fragment. If however, I do a fresh install and I am not connected to a wifi network, the map never gets displayed. The code below executes exactly the same in both cases and no errors are shown in the logcat:

In my onCreateView:

rootView = inflater.inflate(R.layout.map_fragment, container, false);
mMapFragment = new SupportMapFragment() {
    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
         super.onActivityCreated(savedInstanceState);
         Log.d("MAP", "on activity created");
         googleMap = mMapFragment.getMap();
         if (googleMap != null) {
              Log.d("MAP", "google map not null");
//                    initializeGoogleMap();
         } else {
              Log.d("MAP", "google map null");
         }
    }
};
getChildFragmentManager().beginTransaction().add(R.id.map, mMapFragment).commit();

Output with wifi on (map displayed):

D/MAP﹕ on activity created
D/MAP﹕ google map not null

Output with wifi off (map not displayed):

D/MAP﹕ on activity created
D/MAP﹕ google map not null

Why is this happening? What can I do to rectify this issue? At the moment I'm stumped. Thank you in advance!

Lunchbox
  • 1,538
  • 2
  • 16
  • 42
  • do you have any other Internet connection sources ? if so, are you sure that Internet connection is actually available (not just "connected to network" but you can actually receive data (test with making a simple HTTP request to your favorite website for example). – mithrop Feb 18 '15 at 09:44
  • @mithrop, Internet connection is definitely available on the wifi network. Could it be that the map can only be displayed when the user is connected to the internet and not when on 3G/H ? – Lunchbox Feb 18 '15 at 09:47
  • that was my question : do you have any other Internet source when you turn off your wifi. And are you sure you 3G/H is "working correctly" ? – mithrop Feb 18 '15 at 09:48
  • Yes it is, I can make service calls using my mobile data @mithrop – Lunchbox Feb 18 '15 at 09:50
  • any idea about the "connection speed" or connection quality ? – mithrop Feb 18 '15 at 09:51
  • Possible duplicates : http://stackoverflow.com/questions/10772918/google-map-update-with-wifi-but-not-with-3g http://stackoverflow.com/questions/20742461/google-static-map-issue-not-displaying – mithrop Feb 18 '15 at 10:01
  • Try regenerating your API KEY and change in manifest, It might work – Jayanth Feb 18 '15 at 10:04
  • @mithrop, Connection quality is about three bars, I think I will try using the signed api key – Lunchbox Feb 18 '15 at 10:04
  • @Jayanth, Thanks, thats how I got it in the first place, and accepted answer below – Lunchbox Feb 18 '15 at 10:14

1 Answers1

2

If nothing is working, then you could also check if you have restricted the background data of Google Play Services. If you have, try to uncheck the restriction and then try again... More info about how to "unrestrict" the background data here.

Hope this helps...

miselking
  • 3,043
  • 4
  • 28
  • 39