osm存储在数据库中绘制的路径

时间:2014-06-20 16:05:11

标签: java osmdroid android-event

场景:在android中使用OSM,用户在地图上手动绘制路径并单击“保存”按钮,以数据库形式保存为字符串。

        Polyline myPolyline;

      /*
          updating myPolyline  here
      */

      SavePathButton.setOnClickListener(new View.OnClickListener() 
      {
        public void onClick(View arg0) 
        {   
                String tempGeoPointString="Begin";
                String fullPathStore="Begin ";
            List<GeoPoint> myPathPoints=new ArrayList<GeoPoint>(myPathOverLay.getNumberOfPoints());
            Collections.copy(myPathPoints, (myPolyline.getPoints()));   
            for (int i = 0; i < myPathPoints.size(); i++) 
            {
                    GeoPoint tempGeoPoint = myPathPoints.get(i);
                    tempGeoPointString=     String.valueOf(tempGeoPoint.getLatitude())+"#"+String.valueOf(tempGeoPoint.getLongitude());
                    fullPathStore=fullPathStore+tempGeoPointString;

            }
        }

    Log.d("Full Path is ",fullPathStore);
    Log.d("PolyLine Size",myPolyline.getNumberOfPoints());
    Log.d("PathPoints size",myPathPoints.size()
    });

以下是对Polyline class

的引用

myPolyline.getNumberOfPoints()非零,但fullPathStore未更新,myPathPoints.size()在日志中保持为零。 Collecions.copy使用不正确?

1 个答案:

答案 0 :(得分:0)

我不确定“Collections.copy(myPathPoints,(myPolyline.getPoints()));”正确复制GeoPoints。

但是myPolyline.getPoints()已经提供了折线点的副本。 所以不要再复制它,浪费时间和记忆。只是做:

List<GeoPoint> myPathPoints = myPolyline.getPoints();