简体   繁体   中英

Android: Google Maps API v2 rendering issue with markers and camera animation

EDIT

I've found a better STR:

  1. Make sure to set "Do not keep activities" in Developer options in Settings.
  2. Open the app with a SupportMapFragment as a child fragment of another fragment.
  3. Switch to another app
  4. Open your app again
  5. Notice you can't interact with the map and no animations work.
  6. Open another screen within the app
  7. Notice there's a single frame or so of the map with the markers drawn on screen.

I have an issue with Google Maps API v2.

I am animating the camera to zoom to a set of custom marker bitmaps rendered on a MapFragment.

On selecting one of these marker tooltips I open a geo: intent (for the Google Maps app etc.)

When the user presses back it reopens my activity with the fragment back stack rebuilt.

My issue is that it doesn't render camera animations or the markers on coming back, though there is a brief display of those markers when the user presses back to go to the previous fragment.

The GoogleMap instance has the markers, but it doesn't render them - I'm guessing because the MapFragment/MapView thinks it doesn't need to be rendered.

How do I force a render of the MapView? Failing that, how do I get the MapView to recognise that the model has changed?

Put these line into on-resume method-

 SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
  googleMap = fm.getMap();
  //display zoom map
     googleMap.moveCamera( CameraUpdateFactory.zoomTo(13.2f));
        // Enabling MyLocation Layer of Google Map
        googleMap.setMyLocationEnabled(true);

A link for the demo here

The issue was to do with the way I was handling my child fragments.

Every time the parent fragment would call onCreate the children fragments would get recreated.

I did the following to handle my child fragments, but there may be a better way:

private static final String TAG_FRAGMENT_MAP = "TagFragmentMap";

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // ...
    if (savedInstanceState == null) {
        // create the fragments for the first time
        ft.add(R.id.view_flip, new SupportMapFragment(), TAG_FRAGMENT_MAP);
        ft.commit();
    }
}

// ...

public void onViewStateRestored(Bundle savedInstanceState) {
    super.onViewStateRestored(savedInstanceState);
    mMapFragment = (SupportMapFragment)findFragmentByTag(TAG_FRAGMENT_MAP);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM