简体   繁体   English

如何调整缩放级别以适应边界,然后在标记偏移中调整中心贴图?

[英]How to adjust zoom level to fit boundary and then center map in marker offset?

I have a google map (com.google.android.gms.maps.GoogleMap) where I have some markers set. 我有一个谷歌地图(com.google.android.gms.maps.GoogleMap),我有一些标记设置。

I am able to, separately, 我能够,分开,

1) adjust zoom level and center the map on a boundary: 1)调整缩放级别并将地图置于边界中心:

mMap.animateCamera(CameraUpdateFactory.newLatLngBounds(getZoomBounds(), 10));

and

2) center the map above one of the markers: 2)将地图置于其中一个标记上方:

LatLng poiSelectedLatLng = new LatLng(markerSelected.getPosition().latitude 
    + offset, markerSelected.getPosition().longitude);

mMap.animateCamera(CameraUpdateFactory.newLatLng(poiSelectedLatLng));

but, for the life of me, I can't just do both, adjust the zoom level using newLatLngBounds and then center the map somewhere else. 但是,对于我的生活,我不能同时做两件事,使用newLatLngBounds调整缩放级别,然后将地图置于其他地方。 Whatever I do last is what I see happening in the map. 无论我做什么,都是我在地图上看到的。

How do I do this? 我该怎么做呢?

For future visitors this is how you can chain camera animations: 对于未来的访客,您可以使用相机动画链接:

map.animateCamera(CameraUpdateFactory.newLatLngBounds(getZoomBounds(), 10), 2000, new CancelableCallback() {

    @Override
    public void onFinish() {
        LatLng poiSelectedLatLng = new LatLng(markerSelected.getPosition().latitude + offset, markerSelected.getPosition().longitude);
        map.animateCamera(CameraUpdateFactory.newLatLng(poiSelectedLatLng));
    }

    @Override
    public void onCancel() {
    }
});

Also see AnimateCameraChainingExampleActivity.java for an example how to chain infinitely. 另请参阅AnimateCameraChainingExampleActivity.java以获取无限链接的示例。

Try using both moveCamera and animateCamera ... 尝试同时使用moveCameraanimateCamera ......

mMap.moveCamera(CameraUpdateFactory.newLatLngBounds(getZoomBounds(), 10));
LatLng poiSelectedLatLng = new LatLng(markerSelected.getPosition().latitude 
    + offset, markerSelected.getPosition().longitude);

mMap.animateCamera(CameraUpdateFactory.newLatLng(poiSelectedLatLng));

moveCamera will move directly to that spot while animateCamera will provide the moving effect. moveCamera将直接移动到那个位置,而animateCamera将提供移动效果。 They are linear in nature so one will happen after the other however layering them as I have done above will provide the potential effect you are looking for. 它们本质上是线性的,所以一个将在另一个之后发生,但是如上所述将它们分层将提供您正在寻找的潜在效果

If you are trying to see the actual movement of both calls on the UI you will need to register for the callback post the completion of the animation as needed. 如果您试图在UI上查看两个调用的实际移动,则需要在完成动画时根据需要注册回调。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何根据标记位置设置Google地图的缩放级别 - How to set zoom level of a Google map according to marker locations Android 放大并以地图中的自定义标记为中心 - Android zoom in and center around custom marker in a map 如何根据缩放级别Google Maps v2制作标记来调整其大小 - How to make a marker adjust its size based on zoom level Google Maps v2 根据缩放级别在地图上缩放自定义标记 - Scale custom marker on map based on zoom level 如何在Android中启用缩放功能的情况下将标记放置在地图底部而不是地图中心(默认情况下)? - How to put marker at bottom of map instead of center(by default) of map with zoom enabled in android? 如何在地图中心设置标记? - How to set marker on center of the map? Android - 如何在Android应用中使用特定位置,缩放级别和标记启动Google地图意图 - Android - How to launch Google map intent in android app with certain location, zoom level and marker 如何在标记上单击动画在最大缩放级别上设置Google地图 - how to set google map on max zoom level with animation on marker click in android Android Map API-更改缩放级别会导致标记位置不正确 - Android map api - changing zoom level causes incorrect marker position 修复Google-Map中两个Marker之间的缩放级别 - Fix zoom level between two Marker in Google-Map
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM