Android 我需要对纬度和经度进行排序。哪个离我现在的位置更近
这是我计算列表之间距离的方法。 我的代码在下面Android 我需要对纬度和经度进行排序。哪个离我现在的位置更近,android,Android,这是我计算列表之间距离的方法。 我的代码在下面 public void calc(){ for(int i = 0; i < mSearchResultModelsToGetAppointments.size(); i++){ Location newLocation = new Location(""); newLocation.setLatitude(gpsTracker.getLatitude()); newLocation.setLongitude(gpsTr
public void calc(){
for(int i = 0; i < mSearchResultModelsToGetAppointments.size(); i++){
Location newLocation = new Location("");
newLocation.setLatitude(gpsTracker.getLatitude());
newLocation.setLongitude(gpsTracker.getLongitude());
if(String.valueOf(gpsTracker.getLatitude()).equalsIgnoreCase("0.0") || String.valueOf(gpsTracker.getLongitude()).equalsIgnoreCase("0.0")) {
} else{
Location oldLocation = new Location("");
oldLocation.setLatitude(mSearchResultModelUnderProcess.getLatitude());
oldLocation.setLongitude(mSearchResultModelUnderProcess.getLongitude());
float distanceInMeters = newLocation.distanceTo(oldLocation)/1000;
if(distanceInMeters < 2820){
getAdapter().notifyDataSetChanged();
getAdapter().removeItem(i);
getAdapter().notifyDataSetChanged();
}
}
}
}
public void calc(){
对于(int i=0;i
这就是我现在显示位置的方式。如果您不想使用任何外部库,我建议采用以下方式
Happy coding从问题中不清楚问题出在哪里。@Michael我正在得到一个坐标列表,我正在使用distanceto函数计算我当前位置和给定坐标之间的距离。我得到了结果,但现在我必须以这样一种方式列出它们:离我更近的一个应该排在最前面。你觉得我的答案有用吗?如果有,请投赞成票并接受它