0

我只想看看从粗略的位置修复返回的位置是什么形式。像这样使用谷歌代码:

 @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_get_mission);


     // Acquire a reference to the system Location Manager
        LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);

        // Define a listener that responds to location updates
        LocationListener locationListener = new LocationListener() {
            public void onLocationChanged(Location location) {
              // Called when a new location is found by the network location provider.
              makeUseOfNewLocation(location);
            }


            public void onStatusChanged(String provider, int status, Bundle extras) {}

            public void onProviderEnabled(String provider) {}

            public void onProviderDisabled(String provider) {}
          };

        // Register the listener with the Location Manager to receive location updates
        locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);

    }


    private void makeUseOfNewLocation(Location location) {

        TextView locationOutput = (TextView)findViewById(R.id.locationOutput);
        locationOutput.setText((CharSequence) location);

    }

这在我的手机上不起作用,所以我认为这并不容易。我错过了什么?

TIA

当前权限已启用:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
4

1 回答 1

1

您是否在清单中添加了权限?

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> 
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

您还可以获得空的位置,确保能够处理它。

编辑

尝试getLastKnownLocation(LocationManager.GPS_PROVIDER);或添加 wifi 权限。

于 2013-02-27T14:51:28.463 回答