获取用户位置错误

时间:2011-05-13 21:20:54

标签: android mobile gps userlocation

我是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;

我收到如下错误:“类型不匹配:无法从String转换为LocationProvider”

该行的问题是什么

1 个答案:

答案 0 :(得分: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);
}

}

是我在其中一个应用中使用的获取位置信息

问候 西蒙