如何创建一个Android LatLng(两个点)的边界以显示在屏幕顶部?在Android中

时间:2019-03-21 06:56:19

标签: android google-maps bounds google-polyline

enter image description here

我有两个LatLng坐标点。然后我根据该坐标绘制一条折线。如何使多段线图适合屏幕顶部并缩小以查看全线? LatLngBounds.Builder是否是正确的解决方案?

这些是我现在正在使用的代码

LatLngBounds.Builder builder = new LatLngBounds.Builder();

//latlong  and latlong1 are my two points.

        String[] latlong = pickUp.split(",");
        LatLng location = new LatLng(Double.parseDouble(latlong[0]), Double.parseDouble(latlong[1]));
        String[] latlong1 = destination.split(",");
        LatLng location1 = new LatLng(Double.parseDouble(latlong1[0]), Double.parseDouble(latlong1[1]));

        builder.include(location);
        builder.include(location1);


        LatLngBounds bounds = builder.build();
        int padding = 40; 
        CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, padding);
        mMap.animateCamera(cu);

0 个答案:

没有答案