Android地图V2 newLatLngBounds带轴承 [英] Android maps V2 newLatLngBounds with bearing
问题描述
我使用的是最新的Android地图V2用这个布局:
I'm using the new Android maps V2 with this layout:
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"
map:cameraBearing="270"/>
我想使用的方法newLatLngBounds(的LatLngBounds界限,诠释填充)进行放大,看到在地图上所有的标记,但在相机轴承被设置为0。
I'm trying to use the method newLatLngBounds (LatLngBounds bounds, int padding) for zooming and seeing all my markers in the map, however the camera bearing is set to 0.
在谷歌开发者文档中描述说:
The description on google developers documentation says:
公共静态CameraUpdate newLatLngBounds(的LatLngBounds范围,INT 填充) (...) 。返回CameraUpdate具有0和一个轴承 0倾斜(...)。
public static CameraUpdate newLatLngBounds (LatLngBounds bounds, int padding) (...) . The returned CameraUpdate has a bearing of 0 and a tilt of 0. (...)".
我怎样才能更换轴承的价值?
How can I change the bearing value?
我试过newLatLngBounds的召唤,这样的事情后,设定一个新的轴承编程方式:
I tried to set a new bearing programmatically after the call of newLatLngBounds, something like this:
mMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 100));
mMap.moveCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition.Builder()
.target(mMap.getCameraPosition().target)
.zoom(mMap.getCameraPosition().zoom)
.bearing(270)
.build()));
但是,当我这样做了一些标记不会显示出来。
But when I do this some markers won't show up.
推荐答案
当然可以! 只需使用: <一href="https://developers.google.com/android/reference/com/google/android/gms/maps/GoogleMap#animateCamera(com.google.android.gms.maps.CameraUpdate" rel="nofollow">https://developers.google.com/android/reference/com/google/android/gms/maps/GoogleMap#animateCamera(com.google.android.gms.maps.CameraUpdate, INT,com.google.android.gms.maps.GoogleMap.CancelableCallback)
yes you can! just use: https://developers.google.com/android/reference/com/google/android/gms/maps/GoogleMap#animateCamera(com.google.android.gms.maps.CameraUpdate, int, com.google.android.gms.maps.GoogleMap.CancelableCallback)
和实施CancelableCallback,并把在onFinish()方法: <一href="https://developers.google.com/android/reference/com/google/android/gms/maps/GoogleMap.CancelableCallback#onFinish()" rel="nofollow">https://developers.google.com/android/reference/com/google/android/gms/maps/GoogleMap.CancelableCallback#onFinish()
and implement a CancelableCallback and put in the onFinish() method: https://developers.google.com/android/reference/com/google/android/gms/maps/GoogleMap.CancelableCallback#onFinish()
在code,以更换轴承。 当然,你不会得到一个单一的动画,但一连串的两个,而是它的工作!
the code to change the bearing. Of course you will not get a single animation but a chain of two, but it will work!
mMap.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 100)/*,DURATION_IN_MS_IF_NEEDED*/,new GoogleMap.CancelableCallback(){
@Override
public void onCancel() {
//DO SOMETHING HERE IF YOU WANT TO REACT TO A USER TOUCH WHILE ANIMATING
}
@Override
public void onFinish() {
mMap.animateCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition.Builder()
/*.target(mMap.getCameraPosition().target)
.zoom(mMap.getCameraPosition().zoom)*/
.bearing(270)
.build()));
}
});
我不认为你需要的目标和缩放,我让他们注释掉了,因为它应该由$ P $管理pvious动画
修改 迎向美好的API,我有一个可以工作(我不能测试它现在的方法,请大家看看吧: 具有的LatLngBounds你可以得到什么是最适合的区域(这取决于设备的尺寸,所以你必须让视图尺寸在运行时)的缩放级别,然后,当你有变焦(你有同样的中心中的LatLngBounds),你可以做一个独特的动画相机更新: <一href="https://developers.google.com/android/reference/com/google/android/gms/maps/model/CameraPosition" rel="nofollow">https://developers.google.com/android/reference/com/google/android/gms/maps/model/CameraPosition,构造函数允许设定的值,也可以使用生成器为previously看到。
EDIT Looking better at the API, I have a method that could work (I can't test it for now, please take a look at it: having a LatLngBounds you can get what is the zoom level which best fits the area (it depends on the device dimensions, so you have to get view dimensions at runtime), and then, when you have the zoom (you have also the center of the LatLngBounds), you can do a camera update with one unique animation: https://developers.google.com/android/reference/com/google/android/gms/maps/model/CameraPosition, the constructor allows the set of the values, or you can use the builder as previously seen.
您可以在网上找到各种方法来做到这一点,例如(只是一个快速的网上搜索得到一个JavaScript版本的http://计算器.COM / A /四百十二万零四百三十一分之一千三百二十七万四千三百六十一)
You can find online various ways to do that, for example (just a quick search online obtained a javascript version http://stackoverflow.com/a/13274361/4120431 )
希望这可以帮助您与您的问题!
Hope this can help you with your issue!
这篇关于Android地图V2 newLatLngBounds带轴承的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!