【问题标题】:I have two latlong values. one for source and other for destination..In which format latlong value should pass to find distance between them我有两个 latlong 值。一个用于源,另一个用于目的地.. latlong 值应以哪种格式传递以查找它们之间的距离
【发布时间】:2017-11-08 03:41:22
【问题描述】:
DIRECTION_URL_API = "https://maps.googleapis.com/maps/api/directions/json?"
DIRECTION_URL_API + "origin=" + origin + "&destination=" + destination  + "&sensor=true" + "&mode=" +typeOpt+"&key=" + GOOGLE_API_KEY  ;

我正在使用这种格式,但它不起作用

请给我建议:)

【问题讨论】:

标签: android


【解决方案1】:

【讨论】:

    【解决方案2】:

    请使用以下方法计算两点之间的距离

    /**
     * Returns Distance in kilometers (km)
     */
    public static String distance(double startLat, double startLong, double endLat, double endLong) {
        Location startPoint = new Location("locationA");
        startPoint.setLatitude(startLat);
        startPoint.setLongitude(startLong);
    
        Location endPoint = new Location("locationA");
        endPoint.setLatitude(endLat);
        endPoint.setLongitude(endLong);
    
        return String.format("%.2f", startPoint.distanceTo(endPoint) / 1000); //KMs
    }
    

    方法使用-

    String mDistance  = distance(startLat,
                        startLong,
                        endLat,endLng)).concat("km");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-08-16
      • 2019-06-30
      • 2011-03-28
      • 2013-09-15
      • 2011-12-20
      • 2015-01-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多