2014-09-08 4 views
0

일부 명확하지 않은 이유 때문에 어떤 위치도 얻지 못하고 onLocationChanged()가 호출되지 않았습니다.Android GPS : "NO 위치를 찾았습니다."

<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" 
    /> 
<uses-permission 
    android:name="android.permission.READ_PHONE_STATE" 
    /> 
<uses-permission 
    android:name="android.permission.ACCESS_NETWORK_STATE" 
    /> 
<uses-permission 
    android:name="android.permission.INTERNET" 
    /> 

출력은 다음과 같습니다 :

package com.example.gpsexample; 

import android.location.Location; 
import android.location.LocationListener; 
import android.location.LocationManager; 
import android.os.Bundle; 
import android.os.Handler; 
import android.app.Activity; 
import android.content.Context; 
import android.util.Log; 
import android.view.Menu; 

public class GPS_Location extends Activity implements LocationListener { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     Log.d("~~~","~~~ GPS_Location onCreate"); 
     LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); 
     locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this); 
     locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this); 
     Location l1 = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); 
     Location l2 = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); 
     Log.d("~~~","~~~ GPS_Location getLastKnownLocation ==> "+l1+" "+l2); 
     r.run(); 
    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.main, menu); 
     return true; 
    } 

    @Override 
    public void onLocationChanged(Location location) { 
     Log.d("~~~","~~~ onLocationChanged "+location); 

     int latitude = (int) (location.getLatitude()); 
     int longitude = (int) (location.getLongitude()); 

     Log.i("~~~", "### Latitude: " + latitude + ", Longitude: " + longitude+"\n\n\n###"); 
    } 

    @Override 
    public void onProviderDisabled(String provider) { 
     Log.d("~~~","~~~ onProviderDisabled"+provider); 
    } 

    @Override 
    public void onProviderEnabled(String provider) { 
     Log.d("~~~","~~~ onProviderEnabled "+provider); 
    } 

    @Override 
    public void onStatusChanged(String provider, int status, Bundle extras) { 
     Log.d("~~~","~~~ "+provider+" "+status+" "+extras); 
    } 

    final Handler handler = new Handler(); 
    Runnable r = new Runnable() { 
     @Override 
     public void run() { 
      // TODO Auto-generated method stub 
      LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); 
      Log.d("~~~","~~~ GPS_Location run"); 
      Location l = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); 
      Log.d("~~~","GPS enabled: "+locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)); 
      Log.d("~~~","~~~ GPS_Location getLastKnownLocation ==> "+l); 
      l = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); 
      Log.d("~~~","Network enabled: "+locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)); 
      Log.d("~~~","~~~ Network_Location getLastKnownLocation ==> "+l); 
      handler.postDelayed(this, 5000); 
     } 
    }; 
} 

권한은 내가 위치 설정을 변경하면

D/~~~  (29852): ~~~ GPS_Location run 
D/~~~  (29852): GPS enabled: true 
D/~~~  (29852): ~~~ GPS_Location getLastKnownLocation ==> null 
D/~~~  (29852): Network enabled: true 
D/~~~  (29852): ~~~ Network_Location getLastKnownLocation ==> null 

, 나는 onProviderEnabled() 호출을 볼 수 없습니다.

null 대신 위치를 가져 오는 방법은 무엇입니까?

+0

이다에서 업데이트하시기 바랍니다

locationManager.requestLocationUpdates( LocationManager.NETWORK_PROVIDER, MIN_TIME_BW_UPDATES, MIN_DISTANCE_CHANGE_FOR_UPDATES, this); 

? 연결되어 있는지 확인 하시겠습니까? – Blackbelt

+0

기기를 한 번 다시 시작하려고 시도 했습니까? – GrIsHu

+0

위치 서비스 사용 : 설정 -> 위치 및 보안 -> 내 위치 -> 무선을 선택하고 gps를 사용합니다. – amalBit

답변

0
// The minimum distance to change Updates in meters 
private static final long MIN_DISTANCE_CHANGE_FOR_UPDATES = 10; // 10 meters 

// The minimum time between updates in milliseconds 
private static final long MIN_TIME_BW_UPDATES = 1000 * 60 * 1; // 1 minute 

업데이트 위치 장치의 위치 서비스가 활성화 코드

locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000 * 60 * 1, 10, this); 
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1000 * 60 * 1, 10, this) 
+0

차이가 없습니다 - null, null – 18446744073709551615

+0

에뮬레이터에서 실제 디케스트가 아닌 u로 생각합니다 –

+0

위치 변경에서 사용자의 잠시 lang이 필요합니다. –

관련 문제