0

我在使用位置时遇到问题。一旦我尝试从某个位置获取经纬度,我的代码似乎就会失败。

        String locationProvider = LocationManager.GPS_PROVIDER;
    LocationManager locationManager; 
    Location lastKnownLocation;
    locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
    Log.d(TAG, "manager made");
    lastKnownLocation = locationManager.getLastKnownLocation(locationProvider);
    Log.d(TAG, "location stored");
    double lat = lastKnownLocation.getLatitude();
    double lon = lastKnownLocation.getLongitude();
    Log.d(TAG, "Lat, Long got:" + lat + ", " + lon);
    distBetween(lat, lon);
    Log.d(TAG, "Distance calc complete");
    Intent intent = new Intent(this, ListBuilder.class);
    startActivity(intent);

当我尝试调用 .getLatitude() 和 getLongitude() 时失败

和想法为什么?我有互联网权限并可以访问良好的位置。

4

0 回答 0