Java 计算相同起始目的地和结束目的地之间的距离
如何从编码多段线获得多个纬度和经度之间的距离 当前,方向API计算起点和终点之间的距离。但我也希望能够计算出起点和终点在同一位置时的距离Java 计算相同起始目的地和结束目的地之间的距离,java,android,google-maps,google-directions-api,Java,Android,Google Maps,Google Directions Api,如何从编码多段线获得多个纬度和经度之间的距离 当前,方向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 encodedLatLn
// 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();
//生成包含所有纬度和经度的编码字符串
//用于获取准确的距离,否则谷歌将计算壁橱路径。
字符串encodedLatLngList=PolyUtil.encode(latLngListTemp);
字符串encodedWaypointString=“航路点=enc:”+encodedLatLngList;
RESTClient RESTClient=new RESTClient();
Call Call=RESTClient.getGoogleAppService().getDirectionWithEncodedWaypoints(originLatLng、destinationLatNG、encodedWaypointString);
call.enqueue(新回调(){
@凌驾
公共void onResponse(调用、响应){
if(response.issusccessful()){
方向=response.body();
if(direction.getRoutes().size()>0){
字符串距离=方向.getRoutes().get(0.getLegs().get(0.getDistance().getText();
字符串位置a=direction.getRoutes().get(0.getLegs().get(0.getStartAddress());
String locationB=direction.getRoutes().get(0.getLegs().get(0.getEndAddress());
字符串持续时间=direction.getRoutes().get(0.getLegs().get(0.getDuration().getText();
你试过使用android.location.location吗?有一个函数distanceTo(location)它计算两个位置之间的距离。您可以使用SphereCaltil.computeLength
从计算列表的长度
我知道如何计算两点之间的距离,但我需要计算起点和终点位置相同的多个点之间的距离。为什么您不能计算一对一对地把结果加起来?