谷歌地图折线连接点/圆

时间:2019-02-28 19:06:33

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

enter image description here

正如您在屏幕截图中所见,有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);
    }

编辑: 缩放之前: enter image description here

缩放后enter image description here

1 个答案:

答案 0 :(得分:1)

似乎问题不在于标记本身-缩放时尺寸没有变化。例如,标记可绘制$inject = ['$routeProvider']如:

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));
}

你有类似的东西:

Circle markers

缩放时圆圈的大小不变:

Circle markers zoom