我試圖檢查用戶是否處於結束位置(經緯度對象)的邊界,即使當前位置=結束位置,contains函數總是返回false。所有座標都正確更新。我是否錯誤地使用了LatLngBounds?任何想法如何解決它或使用界限的替代?LatLng Bounds contains()總是返回false
protected void changeStep() throws JSONException {
Log.i(TAG, " =========== changeStep ========= ");
int i = 0;
while (i < routes.size()) {
//coordinates for end location
Double latEndLoc = routes.get(i).endLocation.lat;
Double lngEndLoc = routes.get(i).endLocation.lng;
LatLng endLoc = new LatLng(latEndLoc,lngEndLoc);
//setting bounds for end location
LatLngBounds.Builder builder = new LatLngBounds.Builder();
builder.include(endLoc);
LatLngBounds bounds = builder.build();
Log.i("endLoc", endLoc.toString());
Log.i("bounds center", bounds.getCenter().toString());
Log.i("currentLoc", currentLocation.toString());
//checking if users current location is within bounds of end location
if (bounds.contains(currentLocation)) {
Log.i(TAG, " =========== enteredIfBranch ========= ");
setText(i + 1);
return;
}
i++;
}
}
除了這個事實,你不能做任何事情,同積1分,你怎麼確定你考慮終點的「界限」?你至少需要2分 – tyczj