2012-05-29 51 views
1

我能夠獲得銀河流行星系y中當前位置的當前經度和緯度。但是我無法獲得HTC探索中的當前位置?無法獲取HTC探索當前位置的當前緯度和經度?

,我現在用的編碼如下:

@Override 
    protected void onStart() { 

      // TODO Auto-generated method stub 

      super.onStart(); 
      context = Context.LOCATION_SERVICE; 
      locationManager = (LocationManager)getSystemService(context); 
      locationManager.requestLocationUpdates(provider, 1, 1, locationListener); 
      crta = new Criteria(); 
      crta.setAccuracy(Criteria.ACCURACY_FINE); 
      crta.setAltitudeRequired(false); 
      crta.setBearingRequired(false); 
      crta.setCostAllowed(true); 
      crta.setPowerRequirement(Criteria.POWER_LOW); 
      //String provider = locationManager.getBestProvider(crta, true); 
      String provider = LocationManager.GPS_PROVIDER; 
      location = locationManager.getLastKnownLocation(provider); 
      updateWithNewLocation(location); 
      } 

      private void updateWithNewLocation(Location location) { 
         String latLong;    
`enter code here`//      myLocation = (TextView) findViewById(R.id.myLocation); 
         String addressString = "no address found"; 


         if(location!=null) { 
      System.out.println("Provider " + provider + " has been selected."); 
      lat = (Double) (location.getLatitude()); 
      lng = (Double) (location.getLongitude()); 
     // Gomathi 
            double valueofGPSlat = lat * 1000; 
            int GPSsum = (int) valueofGPSlat; 
            GPSvalue = (double) GPSsum/1000; 


            // Get Current Location 
            latt = Double.toString(GPSvalue);                                       
            // Getlon 
            double valueofGPSlng = lng * 1000; 
            int resultGPSsum = (int) valueofGPSlng; 
            resultGPSvalue = (double) resultGPSsum/1000; 
            longt = Double.toString(resultGPSvalue); 
      // GomathiEnd 
         } else { 
         latLong = " NO Location Found "; 
         } 
         //myLocation.setText("your Current Position is :\n" +latLong + "\n " + addressString); 

         Toast.makeText(UsertaskoptionsActivity.this,"your Current Position is :\n" +latt + "\n " + ""+longt , Toast.LENGTH_LONG).show(); 
         } 

      private LocationListener locationListener = new LocationListener() 
      { 
      @Override 
      public void onLocationChanged(Location location) { 
      updateWithNewLocation(location); 
      } 

      private void updateWithNewLocation(Location location) { 
         // TODO Auto-generated method stub 
      } 

      @Override 
      public void onProviderDisabled(String provider) {   
      updateWithNewLocation(null); 
      } 

      @Override 
      public void onProviderEnabled(String provider) { 

      } 

      @Override 
      public void onStatusChanged(String provider, int status, Bundle extras) { 

      } 
      }; 
+0

你會得到任何錯誤? – Lucifer

+0

可能gps在您的手機中無法正常工作,理想情況下您也應該查找網絡提供商地理位置。 – Zoombie

+0

感謝您的幫助。而且我在手機中啓用了GPS,但我仍面臨同樣的問題。 – Yasir

回答

相關問題