2016-05-31 3 views
1

エンコードされたポリラインから複数の緯度と経度の距離を取得する方法を教えてください。同じ開始先と終了先の間の距離を計算する

Currenly Direction APIは、起点と目的地の間の距離を計算します。しかし、私はまた、出発地が同じ場所である場合の距離を計算できるようにしたいと考えています。

// Generates an encoded string with all the latitudes and longitues 
// used to get the exact distance, otherwise the google will calculate the closet path. 
    String encodedLatLngList = PolyUtil.encode(latLngListTemp); 
    String encodedWaypointString = "waypoints=enc:" + encodedLatLngList; 

     RESTClient RESTClient = new RESTClient(); 
     Call<Direction> call = RESTClient.getGoogleApiService().getDirectionWithEncodedWaypoints(originLatLng, destinationLatLng, encodedWaypointString); 
     call.enqueue(new Callback<Direction>() { 

      @Override 
      public void onResponse(Call<Direction> call, Response<Direction> response) { 

      if (response.isSuccessful()) { 

       Direction direction = response.body(); 
      if (direction.getRoutes().size() > 0) { 
       String distance = direction.getRoutes().get(0).getLegs().get(0).getDistance().getText(); 
       String locationA = direction.getRoutes().get(0).getLegs().get(0).getStartAddress(); 
       String locationB = direction.getRoutes().get(0).getLegs().get(0).getEndAddress(); 
       String duration = direction.getRoutes().get(0).getLegs().get(0).getDuration().getText(); 

答えて

1

あなたは、私が2点間の距離を計算する方法を知っているList<LatLng>

1

あなたはandroid.location.Locationを使用しようとしましたか? 2つの場所の間の距離を計算する関数distanceTo(Location)があります。

+0

の長さを計算するためにGoogle Maps API Utility LibraryからSphericalUtil.computeLengthを使用することができますが、私は開始と終了の位置が同じである複数のポイント間の距離を計算する必要があります。 –

+1

ペアでペアを計算してすべての結果を追加できないのはなぜですか? – Meii

関連する問題