我想在用户点击marker时放大。我尝试使用 -
googleMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener()
{
@Override
public boolean onMarkerClick(final Marker marker)
{
googleMap.animateCamera(CameraUpdateFactory.zoomBy(3));
slidingPaneLayout.setPanelHeight(700);
});
我也试过
googleMap.animateCamera(CameraUpdateFactory.zoomIn());
但它没有缩放
答案 0 :(得分:2)
标记上的点击事件可能与缩放动画冲突。您可以尝试添加超时:
import android.os.Handler;
Handler handler = new Handler();
googleMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener()
{
@Override
public boolean onMarkerClick(final Marker marker)
{
handler.postDelayed(new Runnable() {
googleMap.animateCamera(CameraUpdateFactory.zoomBy(3));
}, 200);
return true;
});
这会将动画调用的执行延迟200ms。同时确保返回true
,因为这表明您已经消耗了该事件(请参阅documentation)。 Haven没试过,但这可能会奏效。
答案 1 :(得分:0)
尝试将此代码添加到marker onclick event
{LatLng yournewposition = new LatLng(latitude, longitude);
CameraPosition cameraPosition = CameraPosition.builder()
.target(yournewposition).zoom(10).build();
yourmapobject.animateCamera(CameraUpdateFactory
.newCameraPosition(cameraPosition));}
-Thanks!