想要查找位置(纬度,经度)点是否在移动?

时间:2016-07-21 13:50:57

标签: java collections latitude-longitude

我有位置列表(表示arraylist中的纬度或经度),我想从该列表中找到暂停和移动的位置。请给我一些解决这种情况的方法。

public void find(ArrayList<Location> loclist) {
    for (int i = 0; i < loclist.size()-1; i++) {
        Location loc = loclist.get(i); // this is current location
        double lat = loc.getLatitude();
        double lng = loc.getLongitude();

        Location nextloc = loclist.get(i+1); // this is next location
        double nextlat = nextloc.getLatitude();
        double nextlng = nextloc.getLongitude();

        // now find distance between these points
        double distance = getDistance(loc.getLatitude(), loc.getLongitude(), nextloc.getLatitude(), nextloc.getLongitude());
        if(distance is less than 100 meters means point is halted) {
            // now put this in halted point list 
        } else {
            // add in moving point list
        }
    }
}

1 个答案:

答案 0 :(得分:0)

我认为你的问题的措辞有点令人困惑,但我相信你正试图确定在给定的时间间隔内是否有运动。您可以简单地将一对坐标与之前的坐标进行比较。例如,

ArrayList<Integer> latitude = new ArrayList<Integer>();
ArrayList<Boolean> moving = new ArrayList<Boolean>();
for(int i = 1; i<latitude.size(); i++)
    {
        if(latitude.get(i-1)!=latitude.get(i))
        {
            moving.set(i, true);
        }
        else
        {
            moving.set(i,false);
        }
    }

(想象一下,arraylist充满了纬度值) 现在,一个新的arraylist将填充布尔值,以确定它是否在前一个点和当前点之间“自由地”移动。