如何通过编码多段线获得多个纬度和经度之间的距离。计算相同起始目的地和结束目的地之间的距离
当前方向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();
长度我知道如何两点之间计算距离,但我需要多点在开始和结束位置是相同之间计算距离。 –
为什么你不能通过配对来计算该配对并添加所有结果? – Meii