2017-04-19 2 views
0

webservice에서 위도와 경도 값을 얻고 있는데이를 arraylist에 저장하고 있습니다. arraylist에서 나는 그 값들을 가진 폴리선을 어떤 조건으로 그릴 필요가있다. 조건은 두 개의 위도와 경도의 차이가 1m 이상인 경우입니다. 나는 아주 멀리 떨어져있는 특정한 위도와 긴 값을 피할 필요가있다. 나는 다음 코드 스 니펫을 사용했다.Google지도에서 폴리 라인을 그릴 때 포인트 (LatLng) 피하기

발췌문 :

private void redrawLine() 
    { 

    mMap.clear(); //clears all Markers and Polylines 

    PolylineOptions options = new PolylineOptions().width(3).color(Color.BLUE).geodesic(true); 
    for (int i = 0; i < coordList.size(); i++) { 
    point = coordList.get(i); 
     } 
    for(int j=1; j<coordList.size();j++){ 
     points = coordList.get(j); 
    } 
    CalculationByDistance(point,points); 
    int m = meterInDec*1000; 
    if(m>1){ 
     Toast.makeText(MapsActivity.this, String.valueOf(m), Toast.LENGTH_SHORT).show(); //do nothing 
    } 
    else{ 
     options.add(point); //add points 
    } 
    // addMarker(); //add Marker in current position 
    line = mMap.addPolyline(options); //add Polyline 
} 

방법 CalculationByDistance

public double CalculationByDistance(LatLng StartP, LatLng EndP) { 
    int Radius = 6371;// radius of earth in Km 
    double lat1 = StartP.latitude; 
    double lat2 = EndP.latitude; 
    double lon1 = StartP.longitude; 
    double lon2 = EndP.longitude; 
    double dLat = Math.toRadians(lat2 - lat1); 
    double dLon = Math.toRadians(lon2 - lon1); 
    double a = Math.sin(dLat/2) * Math.sin(dLat/2) 
      + Math.cos(Math.toRadians(lat1)) 
      * Math.cos(Math.toRadians(lat2)) * Math.sin(dLon/2) 
      * Math.sin(dLon/2); 
    double c = 2 * Math.asin(Math.sqrt(a)); 
    double valueResult = Radius * c; 
    double km = valueResult/1; 
    DecimalFormat newFormat = new DecimalFormat("####"); 
    int kmInDec = Integer.valueOf(newFormat.format(km)); 
    double meter = valueResult % 1000; 
    meterInDec = Integer.valueOf(newFormat.format(meter)); 
    Log.i("Radius Value", "" + valueResult + " KM " + kmInDec 
      + " Meter " + meterInDec); 

    return Radius * c; 
} 

사용이 조건을. 선을 그릴 수 없습니다. 조건이 없으면 정상적으로 작동합니다.

+0

CalculationByDistance을 redrawLine 방법의 논리를 변경하거나 필요하거나; for 루프 외부에 있습니다. 단일 점으로 다각형을 그릴 수 없습니다. –

답변

0

포인트 및 포인트 변수에 값을 할당하면 coordList의 마지막 레코드 만 할당됩니다. 계산은 마지막 레코드에만 기반을 둡니다.

for (int i = 0; i < coordList.size(); i++) { 
    point = coordList.get(i); 
} 
for(int j=1; j<coordList.size();j++){ 
    points = coordList.get(j); 
} 
CalculationByDistance(point,points); 

넌 (점, 점) 루프 내부의 거리 계산을 이동하거나

+0

나는 이것과 비슷한 것을 시도했다. 'for (int i = 0; i