获取用户位置错误

发布于 2024-11-06 23:43:58 字数 684 浏览 0 评论 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;

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

该行有什么问题

I am beginner in android development and i am triying to get user location by gps. i give a error in the following code:

 // 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;


            }

in this line

 LocationProvider locationProvider = LocationManager.GPS_PROVIDER;

i get an error like this : "Type mismatch: cannot convert from String to LocationProvider"

what is the problem in that line

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

篱下浅笙歌 2024-11-13 23:43:58

我不知道足够的知识来调试其他人的代码,但这个代码

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

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


西蒙

I don't know enough to debug anyone else's code but this code

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

}

is what I use in one of my apps to get location info

regards
Simon

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文