![](/img/trans.png)
[英]How to animate the camera to a specified location in Google Maps v2 for Android?
[英]Google Maps animate camera doesn't center on location specified
我有一个非常奇怪的问题,我在任何地方都找不到答案。
目标:
当我将模型加载到地图上时,我会从该模型中提取一个点,而该点就是我要设置为相机的新中心的点。
问题:
当我使用map.animateCamera(position)
,相机移动到模型下方。 我无法推断出什么地方出了问题,我已经搜索了文档,但没有找到任何东西。
我如何测试:
为了测试位置是否正确,我在地图上的位置标记了一个标记,并且该标记位于正确的位置,这意味着相机是问题所在。
我也尝试过使用不同的方法map.moveCamera()
以及CameraUpdateFactory.newCameraPosition()
等。
码
private void recenterModel(List<PolygonOptions> t) {
if(t == null || t.isEmpty()) return;
int center = t.size()/2;
PolygonOptions polygon = t.get(center);
while(polygon.getPoints().isEmpty()){
polygon = t.get((++center%t.size()));
if(center > t.size()+1) return; /*If we are here, there aren't any points in model*/
}
center = polygon.getPoints().size()/2;
LatLng centerPoint = polygon.getPoints().get(center);
GoogleMap map = modelMapDrawable.ctx.getMap();
map.animateCamera(CameraUpdateFactory.newLatLngZoom(centerPoint , 15));
map.addMarker(new MarkerOptions().position(centerPoint));
}
在我看来
当我第一次加载应用程序时,它会正确加载项目的中心点。 map.animateCamera()
就像一个吊饰。 每次我做为中心点它的作品。 但是,当我将map.animateCamera()
移至其他位置时,则无法再次使用它。
所以在我看来,相机的坐标系被移动了
请尝试以下方法:
map.animateCamera(CameraUpdateFactory.newLatLngZoom(centerPoint , 15), 2000, new GoogleMap.CancelableCallback() {
@Override
public void onFinish() {
}
@Override
public void onCancel() {
}
});
这将花费一些时间进行动画处理。 我认为,这里的问题是正在处理的动画的即时执行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.