2013-02-27 2 views
0

거친 위치 수정에서 어떤 형태로 위치가 반환되는지보고 싶습니다. 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" /> 
+0

Manifest.xml을 편집하십니까 –

+3

기기 설정에서 Wi-Fi 및 네트워크 위치를 사용하도록 설정 했습니까? – ebarrenechea

+0

예 명시된 위치를 매니페스트에 추가했습니다. –

답변

1

당신이 매니페스트에 권한을 추가 했습니까?

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

또한 null 인 위치를 얻을 수 있습니다. 처리 할 수 ​​있는지 확인하십시오.

편집

getLastKnownLocation(LocationManager.GPS_PROVIDER);을 시도하거나 무선 랜에 대한 권한을 추가합니다.

+0

거친하지만 괜찮은 것은 허용했습니다. –

관련 문제