1

위치 기반 앱에서 작업 중입니다. 여기 내 요구 사항은 uber 또는 Ly ft 앱과 같은 장치에서 사용자 위치를 추적하려고합니다. 예 : 피자 녀석 (사용자 B)이 피자를 나에게 (사용자 A) 전달하려는 경우 사용자 ID를 공유 할 수 있으므로 해당 ID를 사용하여 기기에 입력하고 정확한 정확한 위치를 볼 수 있습니다. 그러나 코드에서이를 달성하는 방법을 요구할 때까지 그를 추적하고 싶습니다. 그런 시나리오를 발견하면 아키텍처를 도와주세요.위치 기반 앱으로 사용자 추적

나는 위의 시나리오를 달성 할 수 있지만 내 위도는 위도와 경도를 확인하고지도에서 업데이트하려면 사용자가 2 분간 움직일 때마다 새로 고침하지 않고 어떻게 맵에 표시 할 수 있습니까? 같은 사용자의 경우

답변

3

처리기에게 위치를 몇 번 가져 오도록 요청하는 스레드를 만듭니다. 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(); 
     } 
    } 
};