2017-04-19 10 views
0

webserviceから緯度と経度の値が取得されています。これらをarraylistに格納しています。 arraylistから、ある条件でそれらの値を持つポリラインを描く必要があります。条件は、2つの緯度、経度の差が1メートルを超える場合です。私は非常に遠い特定の緯度、長い値を避ける必要があります。私は次のコードスニペットを使用しています。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

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); 

あなたがCalculationByDistance(ポイント、ポイント)ループ内距離計算を移動または

+0

私はこれのようなものを試しました。 'for(int i = 0; i

関連する問題