我正在尝试在Google地图v2中绘制路径。
private void drawPath() {
String arrayLatitude[] = { "13.019203", "13.019789", "13.020740",
"13.021398", "13.022026", "13.022768", "13.024022",
"13.024639", "13.025580", "13.026364" };
String arrayLogitude[] = { "80.206267", "80.206342", "80.206385",
"80.206407", "80.206407", "80.206536", "80.206815",
"80.206922", "80.207072", " 0.207523" };
ArrayList<LatLng> points = new ArrayList<LatLng>();
PolylineOptions polyLineOptions = new PolylineOptions();
for (int j = 0; j < arrayLatitude.length; j++) {
// HashMap<String, String> point = path.get(j);
double lat = Double.parseDouble(arrayLatitude[j]);
double lng = Double.parseDouble(arrayLogitude[j]);
LatLng position = new LatLng(lat, lng);
points.add(position);
}
for (int i = 0; i < points.size() - 1; i++) {
LatLng src = points.get(i);
LatLng dest = points.get(i + 1);
Polyline line = googleMap.addPolyline(
new PolylineOptions().add(
new LatLng(src.latitude, src.longitude),
new LatLng(dest.latitude,dest.longitude)
).width(2).color(Color.BLUE).geodesic(true)
);
}
}
但是当我像这样做时,折线被放置在我的地图中,但最后也创建了直线。
我不想要额外的那一行。有什么想法吗?
答案 0 :(得分:0)
你可以试试这种方式
ArrayList<LatLng> points = null;
PolylineOptions polyLineOptions = null;
// traversing through routes
for (int i = 0; i < routes.size(); i++) {
points = new ArrayList<LatLng>();
polyLineOptions = new PolylineOptions();
List<HashMap<String, String>> path = routes.get(i);
for (int j = 0; j < path.size(); j++) {
HashMap<String, String> point = path.get(j);
double lat = Double.parseDouble(point.get("lat"));
double lng = Double.parseDouble(point.get("lng"));
LatLng position = new LatLng(lat, lng);
points.add(position);
}
polyLineOptions.addAll(points);
polyLineOptions.width(2);
polyLineOptions.color(Color.BLUE);
}
googleMap.addPolyline(polyLineOptions);
}
答案 1 :(得分:0)
实施以下代码
col_volume
答案 2 :(得分:0)
String arrayLatitude [] = {“13.019203”,“13.019789”,“13.020740”, “13.021398”,“13.022026”,“13.022768”,“13.024022”, “13.024639”,“13.025580”,“13.026364”};
String arrayLogitude[] = { "80.206267", "80.206342", "80.206385",
"80.206407", "80.206407", "80.206536", "80.206815",
"80.206922", "80.207072", **" 0.207523"** };
不是这个原因吗?看起来你想要80.207523获得最后的经度值。