带有虚线的Google Static Maps API路径 [英] Google Static Maps API Paths with dashed lines

查看:51
本文介绍了带有虚线的Google Static Maps API路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

地图路径中是否可能有虚线?在官方 Google静态地图页面中看不到任何选项./a>.

Is it possible to have dashed line in the map paths? Can't see any option about it in the official Google static map page.

推荐答案

作为解决方法,您可以在

As workaround you can draw dashed line like in example:

List<PatternItem> pattern = Arrays.<PatternItem>asList(new Dash(30), new Gap(20));
mPolyline.setPattern(pattern);

MapView 中在背景上href ="https://developers.google.com/maps/documentation/android-api/lite?hl=zh_CN" rel ="nofollow noreferrer">灯光模式并对其进行快照以获取地图位图,例如那个答案:

over MapView in Light Mode on background and make snapshot of it for getting map bitmap, like in that answer:

public class MainActivity extends AppCompatActivity {

    private static final String MAP_VIEW_BUNDLE_KEY = "MapViewBundleKey";
    static final LatLng KYIV = new LatLng(50.450311, 30.523730);

    private ImageView mImageView;

    private MapView mMapView;
    // dimensions of "static map" image
    private int mMapWidth = 600;
    private int mMapHeight = 800;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mImageView = (ImageView) findViewById(R.id.image_view);

        Bundle mapViewBundle = null;
        if (savedInstanceState != null) {
            mapViewBundle = savedInstanceState.getBundle(MAP_VIEW_BUNDLE_KEY);
        }

        GoogleMapOptions options = new GoogleMapOptions()
                .compassEnabled(false)
                .mapToolbarEnabled(false)
                .camera(CameraPosition.fromLatLngZoom(KYIV,15))
                .liteMode(true);
        mMapView = new MapView(this, options);
        mMapView.onCreate(mapViewBundle);

        mMapView.getMapAsync(new OnMapReadyCallback() {
            @Override
            public void onMapReady(GoogleMap googleMap) {

                // draw dashed path here: 
                List<LatLng> sourcePoints = new ArrayList<>();
                sourcePoints.add(new LatLng(50.440311, 30.523730));
                sourcePoints.add(new LatLng(50.460411, 30.523930));

                PolylineOptions polyLineOptions = new PolylineOptions();
                polyLineOptions.addAll(sourcePoints);
                polyLineOptions.width(10);
                polyLineOptions.color(Color.RED);
                Polyline polyline = googleMap.addPolyline(polyLineOptions);

                List<PatternItem> pattern = Arrays.<PatternItem>asList(new Dash(30), new Gap(20));
                polyline.setPattern(pattern);

                // set map size in pixels and initiate image loading
                mMapView.measure(View.MeasureSpec.makeMeasureSpec(mMapWidth, View.MeasureSpec.EXACTLY),
                        View.MeasureSpec.makeMeasureSpec(mMapHeight, View.MeasureSpec.EXACTLY));
                mMapView.layout(0, 0, mMapWidth, mMapHeight);

                googleMap.setOnMapLoadedCallback(new GoogleMap.OnMapLoadedCallback() {
                    @Override
                    public void onMapLoaded() {
                        mMapView.setDrawingCacheEnabled(true);
                        mMapView.measure(View.MeasureSpec.makeMeasureSpec(mMapWidth, View.MeasureSpec.EXACTLY),
                                View.MeasureSpec.makeMeasureSpec(mMapHeight, View.MeasureSpec.EXACTLY));
                        mMapView.layout(0, 0, mMapWidth, mMapHeight);
                        mMapView.buildDrawingCache(true);

                        // Bitmap b is your "static map"
                        Bitmap b = Bitmap.createBitmap(mMapView.getDrawingCache());
                        mMapView.setDrawingCacheEnabled(false);
                        mImageView.setImageBitmap(b);

                    }
                });

            }
        });
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);

        Bundle mapViewBundle = outState.getBundle(MAP_VIEW_BUNDLE_KEY);
        if (mapViewBundle == null) {
            mapViewBundle = new Bundle();
            outState.putBundle(MAP_VIEW_BUNDLE_KEY, mapViewBundle);
        }
    }
}

这篇关于带有虚线的Google Static Maps API路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆