【问题标题】:How to make polylines show on map with checkbox?如何使用复选框在地图上显示折线?
【发布时间】:2018-09-24 20:08:25
【问题描述】:

我想知道当我点击复选框时如何使折线显示在我的地图上?

【问题讨论】:

    标签: android google-maps polyline


    【解决方案1】:

    定义折线对象

    折线折线;

    使用下面给出的这个类来简单地将你的 FROM 传递到 TO lat,lng

    private class MapDirectionAsync extends AsyncTask<Void, Void, PolylineOptions> {
        private LatLng
                sourceLatLng,
                destinationLatLng;
    
        private MapDirectionAsync(LatLng sourceLatLng, LatLng destinationLatLng) {
            this.sourceLatLng = sourceLatLng;
            this.destinationLatLng = destinationLatLng;
        }
    
        @Override
        protected PolylineOptions doInBackground(Void... params) {
            GMapV2Direction md = new GMapV2Direction();
            Document doc = md.getDocument(sourceLatLng, destinationLatLng, GMapV2Direction.MODE_DRIVING);
            if (doc != null) {
                ArrayList<LatLng> directionPoint = md.getDirection(doc);
                PolylineOptions rectLine = new PolylineOptions().width(16).color(ContextCompat.getColor(TripsActivity.this, R.color.colorPrimary));
    
                float km = Float.parseFloat(md.getDistanceText(doc)) / 1000;
                String km1 = String.format(Locale.US, "%.1f", km);
                Log.e("GoogleMapRoute", "Total KM : " + km1);
    
                int duration = md.getDurationValue(doc);
                Log.e("GoogleMapRoute", "===============Total Duration : " + duration / 60);
    
                for (int i = 0; i < directionPoint.size(); i++) {
                    rectLine.add(directionPoint.get(i));
                }
                return rectLine;
            }
    
            return null;
        }
    
        @Override
        protected void onPostExecute(PolylineOptions rectLine) {
            super.onPostExecute(rectLine);
    
            if (rectLine != null) {
                polyLine = google_Map.addPolyline(rectLine);
            } else {
                // No polyLine available
            }
        }
    }
    

    `

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多