我试图获取位置信息,但一直出现错误。你们当中有人能看到我的问题在哪里吗?其中一个错误至少是"方法不覆盖或实现超类型的方法"。非常感谢大家。
主要内容
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//get Your Current Location
LocationManager locationManager= (LocationManager)getSystemService(Context.LOCATION_SERVICE);
MyCurrentLoctionListener locationListener = new MyCurrentLoctionListener();
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, (LocationListener) locationListener);
}
我的当前位置监听器类
public class MyCurrentLoctionListener implements LocationListener {
@Override
public void onLocationChanged(Location location) {
location.getLatitude();
location.getLongitude();
String myLocation = "Latitude = " + location.getLatitude() + " Longitude = " + location.getLongitude();
//I make a log to see the results
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) {
}
}
在Android清单文件中:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />