2014-05-08 65 views
1

我想在應用程序中獲取用戶的當前位置。每次我用LocationManager得到這個錯誤:LocationManager Android 4.4.1的問題

The method requestLocationUpdates(String, long, float, LocationListener) in the type LocationManager is not applicable for the arguments (String, int, int, MainActivity).

這是我的代碼:

public class MainActivity extends ActionBarActivity implements LocationListener 
{ 
    private GoogleMap googleMap; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); 
       //I get error in this line    
      locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this); 

    } 

    @Override 
    protected void onResume() 
    { 
     super.onResume(); 
    } 

    @Override 
    public void onLocationChanged(Location location) 
    { 
     // TODO Auto-generated method stub 
     double latitude = (double) (location.getLatitude()); 
     double longitude = (double) (location.getLongitude()); 
     Log.i("Geo_Location", "Latitude: " + latitude + ", Longitude: " + longitude); 
    } 

} 

而且LocationListener的實現拋出了我的錯誤,而且必須這樣android.location.LocationListener

任何幫助來實現我會真的很感激。

PD:我使用Eclipse

回答

0

它的很長一段時間,因爲我已經有任何Android的東西的工作,但內置了位置的應用,去年,這是我如何實現位置監聽器,它都能正常運作。

problems with android.location.geocoder

注意:不是所有的鏈接代碼是相對於你的問題,但結構可以有助於