Android的GoogleMap的V2不泛/上刷卡/捏缩放 [英] Android GoogleMap v2 doesn't pan/zoom on swipe/pinch

查看:174
本文介绍了Android的GoogleMap的V2不泛/上刷卡/捏缩放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个的FrameLayout地图V2。如果我不从code动画,它响应触摸通常的方式/刷卡/捏事件。如果我一onLocationChanged()调用,相机移动和缩放动画后它,但随后的地图停止响应用户输入(或至少是感觉)。你轻扫但地图不泛。你捏但是地图并没有放大。你点击...你的想法。

I have a map v2 in a FrameLayout. If I don't animate it from code, it responds to touch/swipe/pinch events in the usual way. If I animate it after a onLocationChanged() call, the camera moves and zooms, but then the map stops responding to user input (or at least that is the feeling). You swipe but the map doesn't pan. You pinch but the map doesn't zoom. You tap... you get the idea.

不过,我偶然有些事情是实际发生的事情发现的,但它没有被显示的某些原因。如果,例如,我刷卡,地图不动,但不知何故记录刷卡。如果我摸home键,这让系统返回到主屏幕,然后在前台再次带来了应用程序,我可以看到我的地图在平移位置,与最远变焦可能的,没有我之前最终添加任何标记。似乎挥动手势通过在纬度= 0,经度= 0为中心,并适用于在地图上重叠隐形地图捕获,并且似乎现在正在显示该地图之一。

However I discovered by chance that something is actually happening, but it's not being shown for some reason. If, for example, I swipe, the map does not move but somehow records the swipe. If I touch the home button, which brings the system back to the home screen, and then bring the app again in foreground, I can see my map in the panned position, with the farthest zoom possible, without any markers I eventually added before. It seems that the swipe gesture was caught by a overlaid invisible map centered in lat=0, lng=0 and applied to that map, and it seems that now that map is the one being shown.

除使用各种断点,很显然,有没有在我的活动所产生的任何其他地图,更不用说透明和覆盖的...我的描述只是为了让你明白这是怎么回事,我不是说,实际上有上面我的另一个地图。

Except that, using various breakpoints, it's clear that there aren't any other maps being created in my activity, let alone transparent and overlaid ones... my description serves only to let you understand what's going on, I'm not suggesting that there actually is another map above mine.

下面是code的相关部分,如果你需要更多的,只是问:

Here are the relevant pieces of code, if you need more, just ask:

我的onCreate()

my onCreate()

@Override
protected void onCreate(Bundle savedInstanceState)
{
  super.onCreate(savedInstanceState);

  setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
  requestWindowFeature(Window.FEATURE_NO_TITLE);
  getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
      WindowManager.LayoutParams.FLAG_FULLSCREEN);

  setContentView(R.layout.map_activity);

}

我在onStart()是:

my onStart() is:

@Override
protected void onStart()
{
  super.onStart();

  // Create the LocationRequest object
  mLocationRequest = LocationRequest.create();
  // Use high accuracy
  mLocationRequest.setPriority(
        LocationRequest.PRIORITY_HIGH_ACCURACY);
  // Set the update interval to 5 seconds
  mLocationRequest.setInterval(UPDATE_INTERVAL);
  // Set the fastest update interval to 1 second
  mLocationRequest.setFastestInterval(FASTEST_INTERVAL);

   mLocationClient = new LocationClient(this, this, this);
   mLocationClient.connect();
}

@Override
public void onConnected(Bundle arg0)
{
  mLocationClient.requestLocationUpdates(mLocationRequest, this);  
}

和我onLocationChanged()是

and my onLocationChanged() is

@Override
public void onLocationChanged(Location loc)
{
  if (mMap == null)
  {
    mapFragment = SupportMapFragment.newInstance();
    FragmentTransaction fragmentTransaction = getSupportFragmentManager()
        .beginTransaction();
    fragmentTransaction.add(R.id.mapcontainer, mapFragment);
    fragmentTransaction.commit();

    mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();

    mMap.getUiSettings().setAllGesturesEnabled(true);
    mMap.getUiSettings().setMyLocationButtonEnabled(true);
    mMap.getUiSettings().setZoomControlsEnabled(true);
    mMap.getUiSettings().setCompassEnabled(true);
    mMap.setMyLocationEnabled(false);

    LatLng location = new LatLng(loc.getLatitude(), loc.getLongitude());
    CameraPosition pos = new CameraPosition.Builder().target(location).zoom(12).build();
    CameraUpdate cu = CameraUpdateFactory.newCameraPosition(pos);
    mMap.animateCamera(cu);

    if (mLocationClient.isConnected())
      mLocationClient.removeLocationUpdates(this);
    mLocationClient.disconnect();

    Log.e(getClass().getSimpleName(), "lat = " + location.latitude + " long = " + location.longitude);
  }
}

请注意,我推迟地图配置,直到第一onLocationChanged()事件,否则地图拒绝动画到请求的位置(见我的其他问题:<一href=\"http://stackoverflow.com/questions/19683146/android-googlemap-v2-ignores-animate-move-calls\">Android: GoogleMap的V2忽略动画/移动电话)。

Please note that I deferred map configuration until the first onLocationChanged() event because otherwise the map refused to animate to the requested location (see my other question for that: Android: GoogleMap v2 ignores animate/move calls ).

推荐答案

您似乎增加了两个 SupportMapFragment s到您的布局。一个用户看到的不是他们交往的人。请确保您添加只有一个片段。

You seem to be adding two SupportMapFragments to your layout. The one user sees is not the one they interact with. Make sure you add only a single fragment.

这篇关于Android的GoogleMap的V2不泛/上刷卡/捏缩放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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