【问题标题】:Android: Google Maps API v2 rendering issue with markers and camera animationAndroid:带有标记和相机动画的 Google Maps API v2 渲染问题
【发布时间】:2013-07-17 05:03:23
【问题描述】:

编辑

我找到了更好的 STR:

  1. 确保在“设置”的“开发者选项”中设置“不保留活动”。
  2. 使用 SupportMapFragment 作为另一个 Fragment 的子 Fragment 打开应用程序。
  3. 切换到另一个应用程序
  4. 再次打开您的应用
  5. 请注意,您无法与地图交互,也无法使用动画。
  6. 在应用中打开另一个屏幕
  7. 请注意,在地图上有一帧左右的标记绘制在屏幕上。

我对 Google Maps API v2 有疑问。

我正在为相机设置动画以缩放到在 MapFragment 上呈现的一组自定义标记位图。

在选择其中一个标记工具提示时,我会打开一个 geo: 意图(用于 Google 地图应用等)

当用户按下它时,它会重新打开我的活动,并重建片段返回堆栈。

我的问题是它不会在返回时呈现相机动画或标记,尽管当用户按下返回以转到上一个片段时会短暂显示这些标记。

GoogleMap 实例有标记,但它不渲染它们 - 我猜是因为 MapFragment/MapView 认为它不需要渲染。

如何强制渲染 MapView?如果做不到这一点,我如何让 MapView 识别模型已更改?

【问题讨论】:

  • 考虑在活动的 onResume() 方法中编写渲染代码。如果可能的话,邮政编码 sn-p 以了解真正的不幸。
  • 贴出代码、短语。

标签: android android-mapview google-maps-android-api-2 supportmapfragment


【解决方案1】:

将这些行放入 on-resume 方法中-

 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);

演示链接here

【讨论】:

    【解决方案2】:

    问题与我处理子片段的方式有关。

    每次父片段调用onCreate 时,子片段都会重新创建。

    我做了以下处理我的子片段,但可能有更好的方法:

    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);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多