简体   繁体   English

修复Google-Map中两个Marker之间的缩放级别

[英]Fix zoom level between two Marker in Google-Map

Currently I work with Google-Map-v2 and I want to show Direction between two Markers . 目前我使用Google-Map-v2 ,我想在两个标记之间显示方向。 Everything is ok and direction between two Markers calculate and draw fine.But only one problem is remain. 一切都很好,两个标记之间的方向计算和绘制正常。但只有一个问题仍然存在。

The problem is Zoom level between these two markers in Google-Map is too much. 问题是Google-Map中这两个标记之间的缩放级别太多了。 I Search in SO and find a solution for changing Zoom Level by Following code : 我搜索SO并找到一个解决方案,通过以下代码更改缩放级别:

 LatLngBounds.Builder builder = new LatLngBounds.Builder();
    builder.include(origin);
    builder.include(dest);
    LatLngBounds bounds = builder.build();

    CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, 50);
    mMap.animateCamera(cu);

Now it's better But still zoom level is not good. 现在它更好但仍然缩放级别不好。 Is it possible to do some fixes on Code ? 是否可以对代码进行一些修复? ( if I can some padding to view is fixed ) (如果我可以修复一些填充)

I Also change 50 to 6,12,... But nothing changed. 我也改50到6,12,......但没有改变。

you are using the correct code, and the value (50) needs to be increased if you want to zoom less (be outer) or decreased to 0 if you want to be in the smallest area containing the two markers (you can skip the value in case). 您正在使用正确的代码,如果您想要缩小(外部)或减少到0,如果您想要在包含两个标记的最小区域中,则需要增加值(50)(您可以跳过该值如果)。

If you set a value of 150 or more, and the level is too much you can use the animation callback to zoom out after the "latlng" zoom: 如果设置值为150或更高,并且级别太高,则可以使用动画回调在“latlng”缩放后缩小:

https://developers.google.com/android/reference/com/google/android/gms/maps/GoogleMap.html#animateCamera(com.google.android.gms.maps.CameraUpdate , com.google.android.gms.maps.GoogleMap.CancelableCallback) https://developers.google.com/android/reference/com/google/android/gms/maps/GoogleMap.html#animateCamera(com.google.android.gms.maps.CameraUpdate,com.google.android.gms 。 maps.GoogleMap.CancelableCallback)

LatLngBounds.Builder builder = new LatLngBounds.Builder();
builder.include(origin);
builder.include(dest);
LatLngBounds bounds = builder.build();

CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, 50);
mMap.animateCamera(cu, new GoogleMap.CancelableCallback(){
    void onCancel(){}
    void onFinish(){
        CameraUpdate zout = CameraUpdateFactory.zoomBy(-3.0);
        mMap.animateCamera(zout);
    }
});

This should zoom to the latLng and when finished, zoom back of 3 levels. 这应该缩放到latLng,完成后,缩放3级。

try this: 尝试这个:

 CameraPosition cameraPosition =
                                    new CameraPosition.Builder()
                                            .target(yourlatlng)
                                           // .bearing(targetBearing)// you can ignore it
                                            .zoom(12)// your zoom value
                                                    // .tilt(40)  // angle of view
                                            .build();


                            mMap.animateCamera(
                                    CameraUpdateFactory.newCameraPosition(cameraPosition),
                                    500,
                                    null);

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM