我在平板电脑上正在获取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面包中,它是:

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

关于android - 在平板电脑上获取经度和纬度为0.0,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20814596/

10-11 00:03