我是安卓开发的初学者,我正在努力通过GPS获取用户位置。 我在以下代码中给出了一个错误:
// Define a listener that responds to location updates
LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
// Called when a new location is found by the network location provider.
// makeUseOfNewLocation(location);
LocationProvider locationProvider = LocationManager.GPS_PROVIDER;
}
在这一行中
LocationProvider locationProvider = LocationManager.GPS_PROVIDER;
我收到这样的错误:"类型不匹配:无法从字符串转换为位置提供程序"
那条线有什么问题
我不知道调试其他人的代码,但这段代码
public class mainActivity extends Activity {
private MyLocationListener mLocationListener;
private LocationManager mLocationManager;
private Location currentLocation;
public class MyLocationListener implements android.location.LocationListener {
public void onLocationChanged(Location location) {
// This is where I finally get the latest location information
currentLocation= location;
int Bearing = (int)currentLocation.getBearing();
}
public void onCreate(Bundle savedInstanceState) {
mLocationManager = (LocationManager) this.getSystemService(LOCATION_SERVICE);
mLocationListener = new MyLocationListener();
}
protected void onResume() {
String provider = LocationManager.GPS_PROVIDER;
long minTime = 0;
float minDistance = 0;
mLocationManager.requestLocationUpdates(provider, minTime, minDistance,mLocationListener);
}
protected void onPause() {
mLocationManager.removeUpdates(mLocationListener);
}
}
是我在其中一个应用程序中用来获取位置信息的内容
问候西蒙