【问题标题】:google maps polyline connected with dots/circles谷歌地图折线与点/圆相连
【发布时间】:2019-02-28 19:06:32
【问题描述】:

正如您在屏幕截图中看到的,有 2 个圆与折线相连。我怎样才能做到这一点?怎么称呼?

我尝试使用带有图标的标记,但是当我放大时,我的图标也在放大并变小。 这是我尝试过的代码:

private void addMarker(LatLng position){

        int height = 50;
        int width = 50;
        BitmapDrawable bitmapdraw = (BitmapDrawable)getResources().getDrawable(R.mipmap.ic_blue_for_marker);
        Bitmap b=bitmapdraw.getBitmap();
        Bitmap smallMarker = Bitmap.createScaledBitmap(b, width, height, false);

        MarkerOptions options = new MarkerOptions()
                .position(position);
        options.icon(BitmapDescriptorFactory.fromBitmap(smallMarker));
        options.anchor(0.5f, 0.5f);
        mMap.addMarker(options);
    }

编辑: 缩放前:

放大后

【问题讨论】:

    标签: android google-maps google-maps-markers


    【解决方案1】:

    似乎问题不在于标记本身 - 缩放时它的大小没有改变。例如标记可绘制ic_blue_circle.xml 喜欢:

    <?xml version="1.0" encoding="utf-8"?>
    <vector xmlns:android="http://schemas.android.com/apk/res/android"
            android:width="496.158dp"
            android:height="496.158dp"
            android:viewportWidth="496.158"
            android:viewportHeight="496.158">
    
        <path
            android:fillColor="#0000FF"
            android:pathData="M496.158,248.085c0-137.021-111.07-248.082-248.076-248.082C111.07,0.003,0,111.063,0,248.085 c0,137.002,111.07,248.07,248.082,248.07C385.088,496.155,496.158,385.087,496.158,248.085z" />
        <path
            android:fillColor="#FFFFFF"
            android:pathData="M351.08,248.083c0-56.891-46.115-103.002-103-103.002c-56.886,0-103.002,46.111-103.002,103.002 c0,56.881,46.116,102.996,103.002,102.996C304.965,351.079,351.08,304.964,351.08,248.083z" />
    </vector>
    

    代码如下:

    @Override
    public void onMapReady(GoogleMap googleMap) {
        mGoogleMap = googleMap;
    
        List<LatLng> sourcePoints = new ArrayList<>();
    
        addCircleMarker(new LatLng(49.182856, -122.844883));
        sourcePoints.add(new LatLng(49.182856, -122.844883));
        sourcePoints.add(new LatLng(49.183452, -122.846288));
        sourcePoints.add(new LatLng(49.183761, -122.846739));
        sourcePoints.add(new LatLng(49.184343, -122.847050));
        sourcePoints.add(new LatLng(49.186917, -122.847061));
        sourcePoints.add(new LatLng(49.188655, -122.847885));
        sourcePoints.add(new LatLng(49.189560, -122.847885));
        addCircleMarker(new LatLng(49.189560, -122.847885));
    
        PolylineOptions polyLineOptions = new PolylineOptions();
        polyLineOptions.addAll(sourcePoints);
        polyLineOptions.width(10);
        polyLineOptions.color(Color.BLUE);
        mGoogleMap.addPolyline(polyLineOptions);
    
        mGoogleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(sourcePoints.get(0), 15));
    }
    

    地点:

    public void addCircleMarker(LatLng latLng) {
        Drawable circleDrawable = ContextCompat.getDrawable(getApplicationContext(), R.drawable.ic_blue_circle);
        BitmapDescriptor markerIcon = getMarkerIconFromDrawable(circleDrawable, 30, 30);
    
        mGoogleMap.addMarker(new MarkerOptions()
                .position(latLng)
                .anchor(0.5f, 0.5f)
                .icon(markerIcon)
        );
    }
    
    private BitmapDescriptor getMarkerIconFromDrawable(Drawable drawable, int width, int height) {
        Canvas canvas = new Canvas();
        Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        canvas.setBitmap(bitmap);
        drawable.setBounds(0, 0, width, height);
        drawable.draw(canvas);
        return BitmapDescriptorFactory.fromBitmap(bitmap);
    }
    

    你得到了类似的东西:

    缩放时圆圈的大小没有改变:

    【讨论】:

    • 但是当我缩小时它变大了
    • 如您所见,我这边没有问题。您的标记矢量是否可绘制?
    • 正如您在 gif 圈中看到的那样,它变得越来越大。我有类似的问题
    • 嗯,好像是一样的。据我所知,标记图标没有改变大小。不过不管怎样,你可以在MapView画布上画圆圈。
    • 我编辑了我的问题,以便您查看我的标记是如何查看的
    猜你喜欢
    • 2018-05-01
    • 2011-07-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-12
    • 2016-05-30
    • 2013-04-04
    • 1970-01-01
    相关资源
    最近更新 更多