在平板电脑上获取经度和纬度为0.0

学习Android

我正在longitude=0.0latitude=0.0平板电脑上,而这是在手机上正常使用。

我使用的LocationManager.NETWORK_PROVIDER不是,GPS_PROVIDER所以可能是什么原因?Logcat输出?

那是我的代码:

 // Acquire a reference to the system Location Manager
         locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);

     // Define a listener that responds to location updates
     locationListener = new LocationListener() {
         public void onLocationChanged(Location location) {
           // Called when a new location is found by the network location provider.
           longitude=location.getLongitude();
           latitude=location.getLatitude();

         }


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

         public void onProviderEnabled(String provider) {}

         public void onProviderDisabled(String provider) {}
       };

     //Or use LocationManager.GPS_PROVIDER
     String locationProvider = LocationManager.NETWORK_PROVIDER;

     // Register the listener with the Location Manager to receive location updates
     locationManager.requestLocationUpdates(locationProvider, 0, 0, locationListener);

     Location lastKnownLocation = locationManager.getLastKnownLocation(locationProvider);

     if(lastKnownLocation!=null){
         longitude=lastKnownLocation.getLongitude();
         latitude=lastKnownLocation.getLatitude();

     }
用户名

在您的设备设置中查看位置设置。这似乎与您的代码无关,但与您的设备设置有关。在我的Ginger面包中,它是:

设置->位置和安全->使用无线网络

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章