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

时间:2013-12-28 12:33:56

标签: android location-provider

我在平板电脑上获得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();

     }

1 个答案:

答案 0 :(得分:1)

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

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