谷歌地图API V2多个地图碎片问题 [英] Google Maps API v2 multiple map fragment problems

查看:152
本文介绍了谷歌地图API V2多个地图碎片问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试一些问题与新的谷歌地图API V2

我有一个包装了mapFragment片段,这是在应用程序的创建乞讨

该在创建另一个片段,当用户点击一个按钮,此内容的其他mapFragment。

但这地图是示出表示在第一片段中的第一图。一个也得到它冻结,它不能使行动...

我读过一些用户有问题,显示屈德宁。任何想法我怎么能解决这个问题?

这是我如何创建地图:

  mMapFragment =(SupportMapFragment)this.getActivity()。getSupportFragmentManager()
            .findFragmentByTag(MAP_FRAGMENT_TAG);    //我们只创建一个片段,如果它不存在。
    如果(mMapFragment == NULL){
        //以编程方式添加地图,我们首先创建一个
        // SupportMapFragment。
        mMapFragment = SupportMapFragment.newInstance();
        mMapFragment.setRetainInstance(假);
        //然后我们使用FragmentTransaction添加。
        FragmentTransaction fragmentTransaction = this.getActivity()。getSupportFragmentManager()
                .beginTransaction();
        fragmentTransaction.add(R.id.ly_map,mMapFragment,MAP_FRAGMENT_TAG);
        fragmentTransaction.commit();
    }其他{
        dbug.log(恢复图);
        mMapFragment.setRetainInstance(假);
        MMAP = mMapFragment.getMap();
    }    //我们不能保证地图可用,因为谷歌播放
    //服务可能
    //不可用。
    setUpMapIfNeeded();


解决方案

无人接听,所以我终于赢得成功对我自己的。

所以,我将分享为其他有同样的问题。
它接缝,有一个错误,如果你有几个片段,并尝试实例化两个或两个以上的地图(谷歌地图)接缝采取同样的实例,previously保存的,即使你使用SupportMapFragment.newInstance()

无论如何,你应该怎么做之前总是关闭地图打开一个新的,所以如果你想显示第二张图,首先用previous地图中删除片段。然后实例化一个新的,并添加到相应的布局。

这不是一个很好的解决方案,因为它意味着打开和关闭的地图每次,但我能找到最好的。

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.

这篇关于谷歌地图API V2多个地图碎片问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆