2

当这在手机上完美运行时longitude=0.0,我正在使用平板电脑。latitude=0.0

我正在使用LocationManager.NETWORK_PROVIDER而不是GPS_PROVIDER那么可能是什么原因?日志输出??

那是我的代码:

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

     }
4

1 回答 1

0

查看设备设置中的位置设置。这似乎不是您的代码的问题,而是您的设备设置的问题。在我的姜饼中,它是:

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

于 2013-12-28T12:53:33.943 回答