【发布时间】:2016-01-10 18:43:37
【问题描述】:
您好,我正在使用 android。我创建了一个应用程序来定位用户的位置。我可以绘制带有相应纬度和经度数组列表值的标记。现在我想在这些标记之间绘制路径。我使用下面的代码来绘制两个标记。那么如何按数组列表的顺序连接所有标记。请帮助我。提前致谢。
private class ParserTask extends
AsyncTask<String, Integer, List<List<HashMap<String, String>>>> {
@Override
protected List<List<HashMap<String, String>>> doInBackground(
String... jsonData) {
JSONObject jObject;
List<List<HashMap<String, String>>> routes = null;
try {
jObject = new JSONObject(jsonData[0]);
PathJsonParser parser = new PathJsonParser();
routes = parser.parse(jObject);
} catch (Exception e) {
e.printStackTrace();
}
return routes;
}
@Override
protected void onPostExecute(List<List<HashMap<String, String>>> routes) {
ArrayList<LatLng> points = null;
PolylineOptions polyLineOptions = null;
try {
// 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);
}catch(NullPointerException e) {
Toast.makeText(
getActivity(),
"Please check your internet connection !",
Toast.LENGTH_LONG).show();
//If data == null it will pass here
}
}
}
private String getMapsApiDirectionsUrl() {
String waypoints = "waypoints=optimize:true|"
+ start.latitude + "," + start.latitude;
String sensor = "sensor=false";
String params = waypoints + "&" + sensor;
String output = "json";
String url = "https://maps.googleapis.com/maps/api/directions/"
+ output + "?" + params;
return url;
}
【问题讨论】:
-
请检查这个答案,希望这会有所帮助。 stackoverflow.com/a/33094777/5093415
标签: android dictionary marker