首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >LocationListener安卓

LocationListener安卓
EN

Stack Overflow用户
提问于 2015-08-25 13:56:49
回答 1查看 968关注 0票数 0

我正在遵循Android开发人员的指南来检索位置,我正试图从它那里获得速度。我按照指南编写了这段代码,但是日志没有打印,文本也没有更新。

代码语言:javascript
复制
        final Button button = (Button) findViewById(R.id.button3);
       final TextView speed = (TextView) findViewById(R.id.textView5);

// Acquire a reference to the system Location Manager
        final LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
        final String locationProvider = LocationManager.GPS_PROVIDER;
// Define a listener that responds to location updates
        final LocationListener locationListener = new LocationListener() {
            public void onLocationChanged(Location location) {
                // Called when a new location is found by the network location provider.
                float getS=(location.getSpeed());
                speed.setText("Speed: "+getS);
            }

            public void onStatusChanged(String provider, int status, Bundle extras) {

                Log.e("",""+status+" "+provider);
            }

            public void onProviderEnabled(String provider) {

            }

            public void onProviderDisabled(String provider) {}
        };


        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (running == 0) {
                    running = 1;
                    button.setText("Stop measuring");
                    locationManager.requestLocationUpdates(locationProvider, 0, 0, locationListener);

                } else {
                    running = 0;
                    button.setText("Start measuring");
                    locationManager.removeUpdates(locationListener);
                }
            }
        });
EN

回答 1

Stack Overflow用户

发布于 2015-08-25 14:04:45

在代码中似乎没有问题。您正在使用GPS_PROVODER获取位置。从GPS.You获取位置可能会有问题,应该首先验证GPS在您的设备上是否正常工作。你可以通过使用谷歌地图应用程序并在移动设备时检查位置来完成此操作。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32196512

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档