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" />
您是否編輯過Manifest.xml – 2013-02-27 14:52:29
您是否在設備的設置中啓用了無線網絡和網絡位置? – ebarrenechea 2013-02-27 14:53:32
是的,我已將COARSE位置添加到清單。 – 2013-02-27 15:03:12