2013-04-17 5 views
0

나는 타워 ID와 gps를 사용하여 GPS 위치를 얻고 있습니다. 현재 위치를 얻고 토스트에 표시 할 수 있습니다. 자동으로 매 5 분마다 그것을 제거해야하며, 안드로이드 장치의지도에 표시해야합니다. 아무도 도와 줄 수 있습니다. 나를. 내 코드는gps 위치를 자동으로 얻는 방법 android?

public void onClick(View arg0) {   
       // create class object 
       gps = new GPSTracker(AndroidGPSTrackingActivity.this); 

       // check if GPS enabled  
       if(gps.canGetLocation()){ 

        double latitude = gps.getLatitude(); 
        double longitude = gps.getLongitude(); 

        // \n is for new line 
        Toast.makeText(getApplicationContext(), "Your Location is - \nLat: " + latitude + "\nLong: " + longitude, Toast.LENGTH_LONG).show();  
       }else{ 
        Toast.makeText(getApplicationContext(),"cant get location", 1000).show(); 
        // GPS or Network is not enabled 
        // Ask user to enable GPS/network in settings 
        gps.showSettingsAlert(); 
       } 

      } 

답변

0

입니다. LocationManager.requestLocationUpdates를보세요. 위치 제공 업체가 업데이트되면 자동으로 업데이트됩니다. 해당 API에서 최대 빈도를 5 분으로 설정할 수 있습니다. 답장을 보내

0
thread1=new Thread(new Runnable() { 

      public void run() { 
       // TODO Auto-generated method stub 
       while (true) { 
        try { 
         Thread.sleep(1000*60*5); 
         mHandler.post(new Runnable() { 


          public void run() { 
           // TODO Auto-generated method stub 
           // Write your code here to update the UI. 
         }); 
        } catch (Exception e) { 
         // TODO: handle exception 
        } 
       } 
      } 
     }); 
+0

감사를 어떻게 u는 너무 백그라운드에서 계속 실행하기 시작하면, 그 스레드 이후 모든 fivebminutes –

+0

에 대한 배경에서이 서비스를 실행하는 저를 표시 할 수 있습니다 .. –

관련 문제