2012-03-09 3 views
-4

현재 최종 프로젝트에 착수하고 있습니다. 나는 안드로이드 운영체제를 사용하는 지능형 함대 관리 시스템이라는 프로젝트를하고 있습니다. GPS 추적기에서 위치 데이터를 가져와 intellitrac x1을 좋아하고 내 안드로이드 응용 프로그램에 표시해야합니다. 이 프로젝트를 시작하는 방법에 대해 혼란 스럽습니다. 나는 너에게서 모든 가이드를 얻을 수 있으면 좋겠다. 고맙습니다.안드로이드 애플리케이션 개발에 대한 제안이 필요합니다.

+0

프로젝트에서 정확히하고 싶은 것이 있습니까? 제발 좀 자세히 설명해주세요. LBS에서 android에서 일했습니다. 그래서 제게 당신의 프로젝트를 안내 할 수 있도록 좀 더 자세한 정보를주세요. – Scorpion

+0

이 프로젝트에서 나는 안드로이드에서 실행되는 함대 관리 응용 프로그램을 개발해야합니다. 응용 프로그램은 GPS 수신기에서 위치 데이터를 가져 와서 Google지도에 표시합니다. – user1258686

+0

기본적으로 위치 (즉, 위도와 경도)를 가져 오시겠습니까? – Scorpion

답변

0

내 앱에 사용 된 코드는 다음과 같습니다. 나는 이것을 사용하여 사용자의 현재 위치를 얻었습니다.

public class AndroidLocationActivity {  
     String provider; 
        public double latitude, longitude = 0; 
        CurrentPositionTask getCurrentLocation; 
        Location currentLocation; 
        LocationListener locationListener; 
        LocationManager locationManager; 
        private long time=0; 

        @Override 
        public void onCreate(Bundle savedInstanceState) { 
         super.onCreate(savedInstanceState); 
         setContentView(R.layout.main); 

         try { 
          locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); 
          setCriteria(); 
          currentLocation = AndroidLocationActivity.this.locationManager.getLastKnownLocation(provider); 

          if (currentLocation == null) { 
           currentLocation = new Location(provider); 
          } 
          time = currentLocation.getTime(); 

          if (latitude == 0 && longitude == 0) { 
           latitude = currentLocation.getLatitude(); 
           longitude = currentLocation.getLongitude();  
          } 

         } catch (NullPointerException e) { 
          // TODO: handle exception 
          System.out.println("Null"); 
          e.printStackTrace(); 
         } 
         catch (Exception e) { 
          // TODO: handle exception 
          e.printStackTrace(); 
         } 

         runAsyncTask();  
        } 

        @Override 
        protected void onDestroy() { 
         // TODO Auto-generated method stub 
         super.onDestroy(); 
         locationManager.removeUpdates(locationListener); 
        } 

        public void setCriteria() { 
         Criteria criteria = new Criteria(); 
         criteria.setAccuracy(Criteria.ACCURACY_FINE); 
         criteria.setAltitudeRequired(false); 
         criteria.setBearingRequired(false); 
         criteria.setCostAllowed(true); 
         criteria.setPowerRequirement(Criteria.POWER_MEDIUM); 
         provider = locationManager.getBestProvider(criteria, true); 
         if (provider == null) { 
          provider = LocationManager.GPS_PROVIDER; 
         } 
        }  


        public void runAsyncTask() { 
         // TODO Auto-generated method stub 
         if (getCurrentLocation == null) { 
          getCurrentLocation = new CurrentPositionTask();  
         } 

         if (getCurrentLocation != null) { 
          getCurrentLocation.execute("Searching for Location");  
         } 
        } 

        public boolean checkConnection() 
        { 
         //ARE WE CONNECTED TO THE NET 

         ConnectivityManager conMgr = (ConnectivityManager) getSystemService (AndroidLocationActivity.CONNECTIVITY_SERVICE); 
         if (conMgr.getActiveNetworkInfo() != null && conMgr.getActiveNetworkInfo().isAvailable()&& conMgr.getActiveNetworkInfo().isConnected()) { 
          return true; 
         } else { 
          return false; 
         } 
        } 


        private class CurrentPositionTask extends AsyncTask<String, Void, Void> 
        { 
         private ProgressDialog Dialog = new ProgressDialog(AndroidLocationActivity.this); 
         private boolean flag = true; 

         public CurrentPositionTask() { 
          locationListener = new MyLocationListener(); 
         } 

         @Override 
         protected void onPreExecute() { 
          // TODO Auto-generated method stub 
          super.onPreExecute(); 
          try { 
           if (checkConnection()) { 
            Dialog.setTitle("Loading"); 
            Dialog.setMessage("Searching for Location"); 
            Dialog.show(); 
            locationManager.requestLocationUpdates(provider, 0, 0, locationListener); 
           } 
           else { 
            Toast.makeText(getApplicationContext(), "Internet is Not Available", Toast.LENGTH_LONG).show(); 
           }  
          } catch (Exception e) { 
           // TODO: handle exception 
           e.printStackTrace(); 
          } 
         } 

         @Override 
         protected Void doInBackground(String... params) { 
          // TODO Auto-generated method stub 
          while (flag) { 
           if (latitude !=0 && longitude != 0) { 
            flag=false; 
           } 
          } 
          return null; 
         } 

         @Override 
         protected void onPostExecute(Void result) { 
          // TODO Auto-generated method stub 
          super.onPostExecute(result); 
          if (Dialog != null && Dialog.isShowing()) { 
           Dialog.dismiss(); 
           Intent homeIntent = new Intent(AndroidLocationActivity.this.getApplicationContext(), nextactivityname.class); 

여기에서 다음 활동이 시작됩니다.

homeIntent.putExtra("lat", latitude); 
     homeIntent.putExtra("lng", longitude); 

          startActivity(homeIntent); 
          } 
          locationManager.removeUpdates(locationListener); 
         } 
        } 

        class MyLocationListener implements LocationListener { 

         @Override 
         public void onLocationChanged(Location location) { 
          // TODO Auto-generated method stub 
          if (location != null) { 
           latitude = location.getLatitude(); 
           longitude = location.getLongitude();  
          } 
         } 

         @Override 
         public void onProviderDisabled(String arg0) { 
          // TODO Auto-generated method stub 
          Toast.makeText(getApplicationContext(),"Gps Disabled",Toast.LENGTH_SHORT).show(); 
         } 

         @Override 
         public void onProviderEnabled(String arg0) { 
          // TODO Auto-generated method stub 
          Toast.makeText(getApplicationContext(),"Gps Enabled",Toast.LENGTH_SHORT).show(); 
         } 

         @Override 
         public void onStatusChanged(String arg0, int arg1, Bundle arg2) { 
          // TODO Auto-generated method stub 
         } 
        } 
    } 

은 그래서 당신은 GPS의 도움으로 현재 위치를 얻을 수있는이 방법은 안드로이드에서 제공합니다. 희망이 도움이 될 것입니다 .....

관련 문제