[英]How to zoom in on a marker in a map activity in android
Hi I wanted to know how I can slowly zoom in on a marker in a map activity in android. 嗨,我想知道如何在android地图活动中缓慢放大标记。 Currently my app just opens zoomed in on the marker.
目前,我的应用程序刚刚打开,放大了标记。 I would like it to zoom in slowly when the app is opened.
打开应用程序后,我希望它缓慢放大。
This is my current code 这是我当前的代码
LatLng mark = new LatLng(21.197384, 6.369441);
mMap.addMarker(new MarkerOptions().position(mark).title("Marker for Mark"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(mark));
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(mark, zoomLevel));
Use mMap.animateCamera
instead of mMap.moveCamera
使用
mMap.animateCamera
而不是mMap.moveCamera
Also, you can control the duration of the movement using 另外,您可以使用以下命令控制移动的持续时间
animateCamera (CameraUpdate update, int durationMs, GoogleMap.CancelableCallback callback)
In your example, change 在您的示例中,更改
mMap.moveCamera(CameraUpdateFactory.newLatLng(mark));
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(mark, zoomLevel));
for 对于
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(mark, zoomLevel));
or, if you want the movement to last 200ms: 或者,如果您希望运动持续200ms:
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(mark, zoomLevel), 200, null);
Try mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(mark, zoomLevel));
试试
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(mark, zoomLevel));
instead of 代替
mMap.moveCamera(CameraUpdateFactory.newLatLng(mark));
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(mark, zoomLevel));
In this way you can achieve this -- 通过这种方式,您可以实现-
CameraUpdate center= CameraUpdateFactory.newLatLng(new LatLng(latitude_origin, longitude_origin));
CameraUpdate zoom = CameraUpdateFactory.newLatLngZoom(new LatLng(latitude_origin, longitude_origin),3);
googleMap.animateCamera(center);
googleMap.animateCamera(zoom);
Hope this helps! 希望这可以帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.