我有一个地图v2在FrameLayout。如果我不用代码对它进行动画处理,它会以通常的方式响应触摸/轻扫/捏动事件。如果在onLocationChanged()调用之后为其设置动画,摄像机会移动并缩放,但地图会停止响应用户输入(或者至少是这种感觉)。你滑动但地图不平移。你捏,但地图不缩放。你点击...你明白了。Android谷歌地图v2不能平移/缩放滑动/捏
但是我偶然发现有些事情正在发生,但由于某种原因没有显示。例如,如果我滑动,地图不会移动,但会以某种方式记录滑动。如果我触摸主页按钮,将系统带回主屏幕,然后再次将应用程序放在前台,我可以看到我的地图处于平移位置,可以进行最远的缩放,没有任何我最终添加的标记。似乎滑动手势被以lat = 0,lng = 0为中心的叠加不可见地图捕捉并应用于该地图,现在看起来该地图是正在显示的地图。
除了使用各种断点,很明显在我的活动中没有创建任何其他地图,更不用说透明和重叠的地图了...我的描述只是为了让你明白发生了什么,我并不是说实际上有另外一张地图。
这里是代码中的相关片段,如果你需要更多的,只是问:
我的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()是:
@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()是
@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()事件,否则地图拒绝为请求位置设置动画(请参阅我的另一个问题:Android: GoogleMap v2 ignores animate/move calls)。
'map_activity.xml'的内容是什么? –