【问题标题】:Google Maps animate camera doesn't center on location specified谷歌地图动画相机不以指定的位置为中心
【发布时间】:2018-03-27 02:02:18
【问题描述】:

我有一个非常奇怪的问题,我无法在任何地方找到答案。

目标:
当我将模型加载到地图上时,我会从该模型中提取一个点,该点就是我想要设置为新相机中心的点。

问题:
当我使用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() 时,我无法让它再次工作。
所以在我看来,相机的坐标系被移动了

【问题讨论】:

  • 你有没有找到解决办法。在我的情况下,它就像将提供的经纬度移动到屏幕的左上角。不知道如何处理。

标签: android google-maps


【解决方案1】:

请试试这个:

map.animateCamera(CameraUpdateFactory.newLatLngZoom(centerPoint , 15), 2000, new GoogleMap.CancelableCallback() {
    @Override
    public void onFinish() {

    }

    @Override
    public void onCancel() {

    }
});

这将给动画一些时间。我认为,这里的问题在于正在处理的动画的即时执行。

【讨论】:

  • 对不起,昨天忘记回复你了。那样也行不通……
猜你喜欢
  • 1970-01-01
  • 2017-12-22
  • 2020-12-24
  • 1970-01-01
  • 2019-11-07
  • 1970-01-01
  • 1970-01-01
  • 2013-02-08
  • 1970-01-01
相关资源
最近更新 更多