Geolocation - Problems with LocationManager Android 4.4.1

De openkb
Aller à : Navigation, rechercher

Sommaire

Questions

I want to get the current location of the user in my app. Everytime i use the LocationManager get this error:

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

This is my code:

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);
    }

}

Also LocationListener implementations throws me an error, and must be implemented like this android.location.LocationListener

Any help I will really appreciate.

PD: I m using Eclipse

Answers

Its a long time since I have worked with any android stuff but built a location app last year and this is how I implemented the location listener and it all worked fine.

http://stackoverflow.com/questions/13906380/problems-with-android-location-geocoder http://stackoverflow.com/questions/13906380/problems-with-android-location-geocoder

NOTE: Not all code at the link is relative to your problem but the structure may help

Source

License : cc by-sa 3.0

http://stackoverflow.com/questions/23554244/problems-with-locationmanager-android-4-4-1

Related

Outils personnels
Espaces de noms

Variantes
Actions
Navigation
Outils