エンコードされたポリラインから複数の緯度と経度の距離を取得する方法を教えてください。同じ開始先と終了先の間の距離を計算する
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();
の長さを計算するためにGoogle Maps API Utility Libraryから
SphericalUtil.computeLength
を使用することができますが、私は開始と終了の位置が同じである複数のポイント間の距離を計算する必要があります。 –ペアでペアを計算してすべての結果を追加できないのはなぜですか? – Meii