如何在 google 地图中绘制 gpx 文件

How to draw gpx file in google maps

我实现了一个应用程序,我可以在 gpx 文件中存储用户移动时的所有路径点。我想在 google 地图中绘制路线。我可以通过解析 xml 文件轻松获取经度和纬度信息,但我不知道如何在地图上绘制路径。示例代码将不胜感激。谢谢

            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);
            }
            //add the polyline in google map
            googleMap.addPolyline(polyLineOptions);