2014-06-20 3 views
0

시나리오 : 안드로이드에서 OSM을 사용하면지도에 수동으로 경로를 그려 저장 버튼을 클릭하여 데이터베이스에 문자열로 저장합니다.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() 
    }); 

여기) 폴리 class

myPolyline.getNumberOfPoints (참조의 비 제로이지만 fullPathStore은 업데이트되지 않으며 myPathPoints.size()가 제로 로그에 남아있다. Collecions.copy가 올바르게 사용되지 않았습니까?

답변

0

"Collections.copy (myPathPoints, (myPolyline.getPoints()));" GeoPoint를 올바르게 복사합니다.

그러나 myPolyline.getPoints()는 이미 폴리 라인 점의 복사본을 제공합니다. 다시 복사하지 마십시오. 시간과 메모리가 낭비됩니다. 그냥 수행

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

myPathPoints.size() 여전히 제로 남아 fullPathStore가 업데이트되지 않습니다 :( – user3596356

+0

가 나는 근본 원인의 아이디어를 (폴리 라인은 PathOverlay에서 상속) 당신은 어떻게 당신의 포인트를 배치해야합니까 있다고 생각합니다. addPoint가있는 폴리 라인? 예인 경우 setPoints 만 사용하십시오. – MKer

+0

경로에 하나의 점만 추가해야 setPoints를 사용할 수 없습니다. 점을 추가하려면 – user3596356

관련 문제