{Android App}如何显示距当前位置和指定点的距离?
我已经研究了几个小时,我看到的唯一答案指向我
http://developer.android.com/reference/android/location/Location.html
并使用该方法
public static void distanceBetween(double startLatitude,double startLongitude,double endLatitude,double endLongitude,float [] results)
我需要帮助了解这与我的应用程序有什么关系。这就是我如何检索我的位置。
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);
}
有人可以帮我解决一下如何将我当前的位置导入这个等式,然后在我的应用程序中显示距离吗?
谢谢
没有找到相关结果
已邀请:
2 个回复
焙恍挝厂熄
如果您已经获得了两个位置的纬度和经度,则可以使用此代码。
禽兢玫坞劲
currentKL.distanceTo(referenceL)>>给出以米为单位的距离 meterToKilometer >>将米转换为千米 updateDistance >>此方法接受一个字符串并更新显示距离的文本视图。 干杯