0

I am having a small issue when starting my app. The tiles which should show up are only loaded after tapping on the map... afterwards all seems to work fine!

In logcat I see the following error:

E/EnterpriseContainerManager﹕ ContainerPolicy Service is not yet ready!!!

public class MainActivity extends FragmentActivity {
  private static final String TAG = "MAIN_ACTIVITY";
  private MyLocationListener locListener;
  private SupportMapFragment supportMapFragment;
  private GoogleMap gmap;

  @Override
  protected void onCreate(Bundle savedInstanceState)
  {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    this.setUpMap();
    list = new ArrayList<GPSCoordinates>();

    new Object();
  }

  @Override
  protected void onStart() {
    super.onStart();
    if (gmap == null) {
        gmap = supportMapFragment.getMap();
        Log.i(TAG, "gmap set!");
    }
    if(locListener == null) {
        this.initLocationManager();
    }
    Log.i(TAG, "gmap start!");
  }

  @Override
  protected void onStop() {
    super.onStop();
    Log.i(TAG, "gmap stop!");
  }

  private void setUpMap() {
    GoogleMapOptions options = new GoogleMapOptions();
    options.mapType(GoogleMap.MAP_TYPE_NORMAL)
            .camera(CameraPosition.fromLatLngZoom(new LatLng(47.384906, 15.093149), 25));

    //supportMapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
    if(supportMapFragment == null) {
        supportMapFragment = SupportMapFragment.newInstance(options);
        getSupportFragmentManager().beginTransaction().replace(R.id.map, supportMapFragment).commit();
    }
  }
}


<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="at.ac.unileoben.infotech.paapp.MainActivity"
tools:ignore="MissingPrefix">

  <fragment xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:name="com.google.android.gms.maps.SupportMapFragment" />
</FrameLayout>


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="at.ac.unileoben.infotech.paapp">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="at.ac.unileoben.infotech.paapp.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

<permission android:name="at.ac.unileoben.infotech.paapp.permission.MAPS_RECEIVE" android:protectionLevel="signature"/>

<uses-feature android:glEsVersion="0x00020000" android:required="true"/>

<application
    android:allowBackup="true"
    android:icon="@drawable/icon"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="at.ac.unileoben.infotech.paapp.MainActivity"
        android:label="@string/app_name"
        android:configChanges="orientation|screenSize">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name="at.ac.unileoben.infotech.paapp.SettingsActivity"
        android:label="@string/action_settings" />

    <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="XXX" />
    <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version"/>
  </application>

</manifest>

edit:

i changed the code of my main_activity to the following..

public class MainActivity extends FragmentActivity {

private ArrayList<GPSCoordinates> list;
private static final String TAG = "MAIN_ACTIVITY";
private static Context context;
private MyLocationListener locListener;
private SupportMapFragment supportMapFragment;
private GoogleMap gmap;

@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    this.setUpMap();
    list = new ArrayList<GPSCoordinates>();
    // access context global
    MainActivity.context = getApplicationContext();

    new Object();
}

@Override
protected void onStart() {
    super.onStart();
    if (gmap == null) {
        gmap = supportMapFragment.getMap();
        Log.i(TAG, "gmap set!");
    }
    if(locListener == null) {
        this.initLocationManager();
    }
    Log.i(TAG, "gmap start!");
}

@Override
protected void onResume() {
    super.onResume();
    Log.i(TAG, "gmap resume!");
}

private void setUpMap() {
    if(supportMapFragment == null) {
        supportMapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
    }
}

later on im calling my simulatelocationmanager with:

private void initLocationManager() {
    locListener = new MyLocationListener(gmap);
    // Define a listener that responds to location updates

    // Register the listener with the Location Manager to receive location updates
    SimulateLocationManager simulatedLocationManager = new SimulateLocationManager();

    //LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
    simulatedLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1, 0, locListener);
    Log.i(TAG, "locListener");
}

in the locationmanager i call the function viewlocation onlocationchanged

public void viewLocation(double latitude, double longitude)
{
    float bearing = this.bearing();
    Log.i(TAG2, "bearing" + bearing);
    gmap.animateCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition.Builder()
            .target(new LatLng(latitude, longitude))
            .bearing(bearing)
            .tilt(55f)
            .zoom(gmap.getCameraPosition().zoom).build()));
}

as i allready said before the problem is that the tiles arent shown till i tap on the map.. all the other things seem to work because i can see the camera moving. but why are the tiles not loaded?

thank you for your reply!

woipi
  • 43
  • 9

1 Answers1

0

Already accepted answer is there about your issue :Find here

If you set up the SupportMapFragment via the <fragment> element in the layout, you can call getMap() successfully in onCreate(). But, if you create the SupportMapFragment via the constructor, that's too soon -- the GoogleMap does not yet exist. You can extend SupportMapFragment and override onActivityCreated(), as getMap() is ready by then.

However, getMap() can also return null for a bigger problem, such as Google Play Services not being installed. You would need to use something like GooglePlayServicesUtil.isGooglePlayServicesAvailable() to detect this condition and deal with it however you wish.

Community
  • 1
  • 1
learner
  • 3,092
  • 2
  • 21
  • 33
  • so now i restored my old version of the code where i set it up in the layout.. it is working fine as long as i have commented the locationlistener.. im calling the locationlistener with locListener = new MyLocationListener(gmap); in the class i am changing the cameraview onlocationchanged.. somehow this is again causing the same problem.. can you tell me why? – woipi Apr 07 '14 at 16:20