2016-07-21 62 views
-2

我有位置列表(意思是緯度或經度在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 
     } 
    } 
} 
+2

你是什麼意思,暫停和移動位置?什麼是暫停的位置?什麼是移動的? – Jokab

+0

停止表示緯度經度相同超過2點。手段點是在相同的GPS位置。 –

回答

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將充滿布爾值作爲它的先前的點與當前點「latitudinaly」之間是否被移動。