小编Hon*_*gry的帖子

如何在Android中获得经度和纬度

我想找到我当前位置的经度和纬度,但我一直得到NULL.

double lat = loc.getLatitude(); //Cause the result is null, so can't know longitude and latitude
double lng = loc.getLongitude();


 LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);  
    String provider = LocationManager.GPS_PROVIDER;  
    Location location = locationManager.getLastKnownLocation(provider); //result is null!
Run Code Online (Sandbox Code Playgroud)

这是获取GPS状态的代码.它工作正常:

public void onGpsStatusChanged(int event) { // get the GPS statue  
                LocationManager locationManager = (LocationManager) GpsActivity.this.getSystemService(Context.LOCATION_SERVICE);  
                GpsStatus status = locationManager.getGpsStatus(null);  
                String satelliteInfo = updateGpsStatus(event, status);
                myTextView.setText(satelliteInfo);//work fine ,searched satellite:16
    }
    };
        private String updateGpsStatus(int event, GpsStatus status) {  
            StringBuilder sb2 = new …
Run Code Online (Sandbox Code Playgroud)

android android-location

3
推荐指数
1
解决办法
5316
查看次数

标签 统计

android ×1

android-location ×1