2013-04-15 28 views
0

在我的Android應用程序,我試圖比較用戶的位置與商店座標列表。比較我的GPS位置列表 - android

我已經知道如何獲取用戶座標,並且我已經有了一個列表作爲數組。

如何比較兩者並找到最近的商店?

回答

1
float shortestDistance = Float.MAX_VALUE; 
Location closestLocation = null; 
for(Location loc : locations){ 
    if(yourLocation.distanceTo(loc) < shortestDistance){ 
     shortestDistance = yourLocation.distanceTo(loc); 
     closestLocation = loc; 
    } 
}