【发布时间】:2012-07-11 14:26:41
【问题描述】:
我已经研究了几个小时,我看到的唯一答案指向我 http://developer.android.com/reference/android/location/Location.html
并使用方法
public static void distanceBetween (double startLatitude, double startLongitude, double endLatitude, double endLongitude, float[] 结果)
我需要帮助来了解这与我的应用程序相关的工作原理。这就是我检索我的位置的方式。
LocationManager locationManager;
String context = Context.LOCATION_SERVICE;
locationManager = (LocationManager)getSystemService(context);
String provider = LocationManager.GPS_PROVIDER;
Location location = locationManager.getLastKnownLocation(provider);
updateWithNewLocation(location);
}
private void updateWithNewLocation(Location location) {
String latLongString;
TextView myLocationText;
myLocationText = (TextView)findViewById(R.id.myLocationText);
if (location != null) {
double lat = location.getLatitude();
double lng = location.getLongitude();
latLongString = "Lat:" + lat + "\nLong:" + lng;
} else {
latLongString = "No location found";
}
myLocationText.setText("Your Current Position is:\n" +
latLongString);
}
有人可以帮我理解一下如何将我当前的位置导入这个等式,然后在我的应用程序中显示距离吗? 谢谢你
【问题讨论】:
-
首先您没有获得 当前 位置,请使用 requestSingleUpdate() 来执行此操作。其次,您正在计算当前位置与 .... 之间的距离?