如何使复选框在地图上显示多段线? [英] How to make polylines show on map with checkbox?
本文介绍了如何使复选框在地图上显示多段线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
解决方案
定义对象折线
折线polyLine;
使用下面给出的这个类来简化线,只是将您的FROM传递给TO lat ,lng
private class MapDirectionAsync extends AsyncTask< Void,Void,PolylineOptions> {
私人LatLng
sourceLatLng,
destinationLatLng;
私有MapDirectionAsync(LatLng sourceLatLng,LatLng destinationLatLng){
this.sourceLatLng = sourceLatLng;
this.destinationLatLng = destinationLatLng;
$ b @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,===============总持续时间:+持续时间/ 60);
for(int i = 0; i< directionPoint.size(); i ++){
rectLine.add(directionPoint.get(i));
}
return rectLine;
}
返回null;
}
@Override
protected void onPostExecute(PolylineOptions rectLine){
super.onPostExecute(rectLine);
if(rectLine!= null){
polyLine = google_Map.addPolyline(rectLine);
} else {
//无多行文本
}
}
}
`
I was wondering how can I make polylines to show on my map when I click on checkbox?
解决方案
Define object of polyline
Polyline polyLine;
Use this class given below to drab the lines just pass your FROM to 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
}
}
}
`
这篇关于如何使复选框在地图上显示多段线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文