-3

Sir, thanks for your help, here is the complete code of my program. hi I am getting error "cannot resolve method locationmanager.requestLocationUpdates();

public class MainActivity extends Activity implements LocationListener {

public Button button;
private TextView textView;
public LocationManager locationmanager;
Context context;
private double lat,lon;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    locationmanager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);


    button = (Button) findViewById(R.id.button);
    textView = (TextView) findViewById(R.id.textView);

    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            //error !!!!!!

**Error ** locationmanager.requestLocationUpdates(LocationManager.GPS_PROVIDER,5000,0,this);

        }
    });
}

@Override
public void onLocationChanged(Location location) {
    if(location!=null)
    {
        lat=location.getLatitude();
        lon=location.getLongitude();
        textView.append("\n lat:"+lat+" lon:"+lon);
    }

}

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

}

@Override
public void onProviderEnabled(String provider) {

}

@Override
public void onProviderDisabled(String provider) {

}

}

1 Answers1

1

First, do not use "gps". Use LocationManager.GPS_PROVIDER.

Second, this does not match any signature for requestLocationUpdates(). this is a View.OnClickListener, not a LocationListener or a PendingIntent.

If this code is from an activity or fragment, and that activity or fragment is implementing LocationListener, this MyActivity.this instead of this, where MyActivity is the name of the activity or fragment that is implementing LocationListener.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491