I try to get the location, but keep getting errors. Can any of you guys see where I'm wrong? One mistake is at least "the method does not override or does not implement the method from the supertype." - Many thanks to the guys
MAIN
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
LocationManager locationManager= (LocationManager)getSystemService(Context.LOCATION_SERVICE);
MyCurrentLoctionListener locationListener = new MyCurrentLoctionListener();
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, (LocationListener) locationListener);
}
Class MyCurrentLoctionListener
public class MyCurrentLoctionListener implements LocationListener {
@Override
public void onLocationChanged(Location location) {
location.getLatitude();
location.getLongitude();
String myLocation = "Latitude = " + location.getLatitude() + " Longitude = " + location.getLongitude();
Log.e("MY CURRENT LOCATION", myLocation);
}
@Override
public void onStatusChanged(String s, int i, Bundle bundle) {
}
@Override
public void onProviderEnabled(String s) {
}
@Override
public void onProviderDisabled(String s) {
}
}
In android manifest:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
source
share