처리기에게 위치를 몇 번 가져 오도록 요청하는 스레드를 만듭니다. getMyLocation 방법 만 GUI 스레드에서 호출 할 수 있기 때문에, 핸들러를 사용할 필요가 :
여기
private class MyLocationThread extends Thread{
@Override
public void run() {
int loops = 0;
// we give the location search a minute
while(loops < 60){
// we have to try it over a handler, because getMyLocation() has to be called from GUI Thread -_-
_getMyLocationHandler.sendEmptyMessage(0);
if(isInterrupted()){
return;
}
// take a short nap before next try
try {Thread.sleep(1000);} catch(Exception e){}
loops++;
}
}
}
는 핸들러가하는 작업은 다음과 같습니다
private Handler _getMyLocationHandler = new Handler(){
public void handleMessage(android.os.Message msg) {
if(getMap().isMyLocationEnabled() && getMap().getMyLocation() != null){
_locationWatcher.interrupt();
drawCurrentImagePositions();
}
}
};