【发布时间】:2018-10-02 23:01:58
【问题描述】:
我正在尝试根据与用户当前位置的距离对经纬度坐标列表进行排序。我试过使用比较器,但似乎无法让它工作。我尝试了许多不同的方法来实现比较器,包括使用数组列表,并尝试了许多不同的网络教程。我正在考虑使用一个集合然后对其进行排序,但不知道如何。我在正确的轨道上吗?我的代码如下。如果有人能指出我正确的方向,那就太好了。非常感谢!
package com.example.qdogg.mealmapnb;
//@Author Quinn Clark 2018
//
/**
*Sorting based on proximity soon
*/
import android.content.Intent;
import android.location.Location;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
public abstract class SleepMap extends MainActivity implements
OnItemClickListener, LocationProviderSleepMap.LocationProviderListener {
ListView listView;
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sleep_map);
listView = (ListView) findViewById(R.id.sleeplist);
listView.setOnItemClickListener(this);
}
@Override
public void gotCurrentLocation(Location location) {
final Location CLSM = new Location("");
CLSM.setLatitude(location.getLatitude());
CLSM.setLongitude(location.getLongitude());
Location IFCSM = new Location("");
IFCSM.setLatitude(51.042580);
IFCSM.setLongitude(-114.062782);
Location BGCSM = new Location("");
BGCSM.setLatitude(51.039370);
BGCSM.setLongitude(-114.084020);
float CLSMtoIFCSM = CLSM.distanceTo(IFCSM);
float CLSMtoBGC = CLSM.distanceTo(BGCSM);
}
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
switch (position) {
case 0:
Intent innfromthecold = new Intent(this, ifcactivity.class);
startActivity(innfromthecold);
break;
case 1:
Intent boysandgirlsclub = new Intent(this, bgcactivity.class);
startActivity(boysandgirlsclub);
break;
default:
//Nothing
}
}
}
【问题讨论】:
-
gotCurrentLocation()对一些 局部变量 进行一些计算,因此当方法返回时,这些计算值会丢失。您使用ArrayList和Compartor进行描述,但问题中没有包含任何代码。请更新尝试失败的详细信息。