I have experimented few issue with the new google map api v2

I have a fragment that wraps a mapFragment, this is created at the begging of the app.

The in another fragment that is created when the user click on a button, this content an other mapFragment.

But this map is showing the first map that is showing on the first fragment. An also it get frozen and can't make actions on it...

I've read that some users have problems to show multimaps. Any idea how can I solve this?

This is how I create the maps:

mMapFragment = (SupportMapFragment) this.getActivity().getSupportFragmentManager()
            .findFragmentByTag(MAP_FRAGMENT_TAG);

    // We only create a fragment if it doesn't already exist.
    if (mMapFragment == null) {
        // To programmatically add the map, we first create a
        // SupportMapFragment.
        mMapFragment = SupportMapFragment.newInstance();
        mMapFragment.setRetainInstance(false);
        // Then we add it using a FragmentTransaction.
        FragmentTransaction fragmentTransaction = this.getActivity().getSupportFragmentManager()
                .beginTransaction();
        fragmentTransaction.add(R.id.ly_map, mMapFragment,MAP_FRAGMENT_TAG);
        fragmentTransaction.commit();
    } else {
        dbug.log("Restoring map");
        mMapFragment.setRetainInstance(false);
        mMap = mMapFragment.getMap();
    }

    // We can't be guaranteed that the map is available because Google Play
    // services might
    // not be available.
    setUpMapIfNeeded();
有帮助吗?

解决方案

Nobody answer so I finally succed on my own.

So I will share for the others with the same problem. It seams that there is a bug, that if you have several fragments and you try to instanciate two or more maps (Google Maps) seams to take the same instance previously saved, even that you use SupportMapFragment.newInstance()

Anyway, what you should do is always close the map before open a new one, so if you want to show the second map, first of all remove the fragment with the previous map. And then instantiate a new on and add to the correspondent layout.

It's not a really good solution because it means to open and close the maps everytime, but is the best I could find.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top