거친 위치 수정에서 어떤 형태로 위치가 반환되는지보고 싶습니다. Google 코드를 다음과 같이 사용하십시오 :간단한 네트워크 위치 테스트가 작동하지 않습니까?
@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을 편집하십니까 –
기기 설정에서 Wi-Fi 및 네트워크 위치를 사용하도록 설정 했습니까? – ebarrenechea
예 명시된 위치를 매니페스트에 추가했습니다. –