2011-05-13 75 views
0

我是android開發的初學者,我正在試圖通過gps獲取用戶位置。我給下面的代碼一個錯誤:在這一行獲取用戶位置錯誤

// Define a listener that responds to location updates 
      LocationListener locationListener = new LocationListener() { 
      public void onLocationChanged(Location location) { 
       // Called when a new location is found by the network location provider. 
      // makeUseOfNewLocation(location); 

       LocationProvider locationProvider = LocationManager.GPS_PROVIDER; 


      } 

LocationProvider locationProvider = LocationManager.GPS_PROVIDER; 

我得到這樣的錯誤:「類型不匹配:不能從字符串轉換爲LocationProvider」

是什麼在該行的問題

回答

0

我不知道足以調試其他人的代碼,但此代碼

public class mainActivity extends Activity { 

private MyLocationListener mLocationListener; 
private LocationManager mLocationManager; 
private Location currentLocation; 




public class MyLocationListener implements android.location.LocationListener { 


    public void onLocationChanged(Location location) { 
     // This is where I finally get the latest location information 

     currentLocation= location; 

     int Bearing = (int)currentLocation.getBearing(); 

} 


public void onCreate(Bundle savedInstanceState) { 

    mLocationManager = (LocationManager) this.getSystemService(LOCATION_SERVICE); 
    mLocationListener = new MyLocationListener(); 

} 

protected void onResume() { 

    String provider = LocationManager.GPS_PROVIDER; 
    long minTime = 0; 
    float minDistance = 0; 
    mLocationManager.requestLocationUpdates(provider, minTime, minDistance,mLocationListener); 

} 

protected void onPause() { 
    mLocationManager.removeUpdates(mLocationListener); 
} 

}

是我在我的應用程序之一,用它來獲得位置信息

問候 西蒙