0
사용자가 찍은 경로의 모든 지점을 볼 수 있도록 화면의지도를 업데이트해야하는 문제에 직면하고 있습니다.알 수없는지도 업데이트가 완료되었는지 확인하는 방법은 무엇입니까?
아래 코드에서 맵 업데이트를 요청한 횟수를 계산하지만 때로는 요청 수가 콜백 수와 일치하지 않는 것으로 나타났습니다. 그래서 'mapLoaded'가 0이되기를 기다리는 것은 좋은 생각이 아닙니다.
따라서 제한 시간을 10 초로 늘 렸지만 이는 임의적이며 때로는 충분하지 않습니다. 그럼 모든지도 업데이트가 완료되었는지 어떻게 알 수 있습니까?
private void adjustMapCompleteSO(LatLng from, LatLng to){//3.3.17 show all points for screenshot
double x1=(from.latitude+to.latitude)/2;
double x2=(from.longitude+to.longitude)/2;
LatLng del=new LatLng(x1,x2);
map.moveCamera(CameraUpdateFactory.newLatLng(del));
mapLoaded=0;
for(Polyline pol : allcrumbs){
List<LatLng> points = pol.getPoints();
for (LatLng point : points){
LatLngBounds.Builder builder = new LatLngBounds.Builder();
builder.include(point);
LatLngBounds bounds = builder.build();
int padding = 40; // offset from edges of the map in pixels
CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, padding);
mapLoaded++;
map.setOnMapLoadedCallback(new GoogleMap.OnMapLoadedCallback() {
public void onMapLoaded() {
mapLoaded--;
}
});
map.moveCamera(cu);
}
}
Date started = new Date();
while (mapLoaded !=0 && new Date().getTime() - started.getTime() < 10000){
try {//wait until map has loaded, but max 10 seconds
Thread.sleep(500);//wait half a second before tyring again
} catch (InterruptedException e) {}
}
}