本文介绍了Android的地图 - animateCamera()方法不正确工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:

1)地图四处动画以达到在code中的居民点(4号线),但它得到了放大至code,其默认位置(5号线)

[留在默认位置地图在指定的缩放级别]

2)我明白为什么这个问题发生,但我不知道如何解决它。

3)如果我改变四号线到moveCamera,而不是animateCamera,将工作,但我确实希望animateCamera()方法。

这里的code:

 地图=((MapFragment)getFragmentManager()findFragmentById(R.id.map)。)的GetMap()。
的MarkerOptions选项=新的MarkerOptions()位置(经纬度新(13.0810,80.2740))。
map.addMarker(选件);
map.animateCamera(CameraUpdateFactory.newLatLng(新经纬度(13.0810,80.2740)),4000,NULL);
map.animateCamera(CameraUpdateFactory.zoomTo(15.5f),2000,NULL);


解决方案

的问题是,你叫缩放之后你开始动画到新的位置。这就是为什么它只是取代了过去的相机更新动作用新的。

您可以简单地解决,通过建立更加准确的相机更新操作(这将包括经纬度的变化和缩放级别的变化):

  CameraPosition newCamPos =新CameraPosition(新经纬度(13.0810,80.2740)
                                                  15.5f,
                                                  map.getCameraPosition()倾斜,//使用旧倾斜
                                                  map.getCameraPosition()轴承)。 //使用旧轴承
map.animateCamera(CameraUpdateFactory.newCameraPosition(newCamPos),4000,NULL);

或者:由MaciejGórski指出的那样,你可以使用 newLatLngZoom 接口,其中包括两个经纬度缩放的变化:

  map.animateCamera(CameraUpdateFactory.newLatLngZoom(新经纬度(13.0810,80.2740),15.5f),4000,NULL);

Problem:

1) Map getting animated to reach the required location(4th line in code) but it got zoomed to the default location(5th line in code)

[leaving the map in the default location at the specified zoom level]

2) I understand why is the problem happening but i don't know how to resolve it.

3) If i change the 4th line to moveCamera instead of animateCamera that will work, but i do want animateCamera() method.

Here's the code:

map=((MapFragment)getFragmentManager().findFragmentById(R.id.map)).getMap();
MarkerOptions options=new MarkerOptions().position(new LatLng(13.0810,80.2740));
map.addMarker(options);
map.animateCamera(CameraUpdateFactory.newLatLng(new LatLng(13.0810,80.2740)),4000,null);
map.animateCamera(CameraUpdateFactory.zoomTo(15.5f),2000,null);
解决方案

The problem is that you call zoom right after you started animating to the new location. That's why it just replaces last camera update action with the new one.

You can simply resolve that by creating more accurate camera update action (which would include both latlng change AND zoom level change):

CameraPosition newCamPos = new CameraPosition(new LatLng(13.0810,80.2740),
                                                  15.5f,
                                                  map.getCameraPosition().tilt, //use old tilt
                                                  map.getCameraPosition().bearing); //use old bearing
map.animateCamera(CameraUpdateFactory.newCameraPosition(newCamPos), 4000, null);

ALTERNATIVELY as pointed out by MaciejGórski, you can just use newLatLngZoom interface which includes both LatLng and zoom change:

map.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(13.0810,80.2740), 15.5f), 4000, null);

这篇关于Android的地图 - animateCamera()方法不正确工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 04:12