【问题标题】:How to calculate distance and time to location如何计算到位置的距离和时间
【发布时间】:2014-10-24 13:04:22
【问题描述】:

我需要使用 gps 计算当前位置到给定位置之间的时间和距离。

哪位大侠给点意见

  final TextView speedView = (TextView) findViewById(R.id.speedtxt);
     locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
     locationListener = new LocationListener() {
         public void onLocationChanged(Location location) {
             if (location.hasSpeed()) {
                float speed = location.getSpeed() * 3.6f;// km/h
                speedView.setText(String.format("%.0f km/h", speed));
            }
        }
        public void onProviderDisabled(String provider) {
        }

        public void onProviderEnabled(String provider) {
        }

        public void onStatusChanged(String provider, int status, Bundle extras) {
        }
    };

【问题讨论】:

    标签: android gps geolocation


    【解决方案1】:

    Location 具有distanceTo 方法,该方法返回此位置与给定位置之间的近似距离(以米为单位)。例如

    float distance = gpsLocation.distanceTo(dstLocation);
    

    【讨论】:

      【解决方案2】:

      看看Location.distanceBetween(double startLatitude, double startLongitude, double endLatitude, double endLongitude, float[] results)方法

      http://developer.android.com/reference/android/location/Location.html

      //finding the distance between destination and mylocation
      
                      Location.distanceBetween(startLatitude , startLongitude, endLatitude , endLongitude , results);
      // to convert metre to KM
                      if(results[0]>1000)
                      {
                          distString = (double)Math.round(results[0]/1000)+"km";
      
                      }
                      else
                      {
                          distString = Math.round(results[0])+"m";
                      }
                      Log.d("dist string",distString);
      // Store the distances in array
      
                      distance[i]=distString;
      

      顺便问一下,已经有问题了

      Calculating distance between two geographic locations

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-01-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-09-21
        • 2021-03-06
        • 2011-04-03
        • 1970-01-01
        相关资源
        最近更新 更多