0

我是 android 开发的初学者,我正在尝试通过 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;

我收到这样的错误:“类型不匹配:无法从字符串转换为 LocationProvider”

那行有什么问题

4

1 回答 1

0

我对调试其他人的代码知之甚少,但这段代码

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

}

是我在我的一个应用程序中用来获取位置信息的工具

问候西蒙

于 2011-05-13T22:23:01.153 回答