2015-01-14 2 views
0

다음 코드를 붙여 넣기 복사 : link. 에뮬레이터 대신 활성 장치를 사용할 때 위치 정보가 표시되지 않았습니다. 심지어 GPS가 활성화되었습니다GPS에서 위치 정보 수정 없음 - Android

public class UseGps extends Activity 

{ 

    /** Called when the activity is first created. */ 

    @Override 
    public void onCreate (Bundle savedInstanceState) 

    { 

     super.onCreate (savedInstanceState); 

     setContentView (R.layout.main); 

     /* Use the LocationManager class to obtain GPS locations */ 

     LocationManager mlocManager = (LocationManager) getSystemService (Context.LOCATION_SERVICE); 

     LocationListener mlocListener = new MyLocationListener(); 

     mlocManager.requestLocationUpdates (LocationManager.GPS_PROVIDER, 0, 0, mlocListener); 

    } 

    /* Class My Location Listener */ 

    public class MyLocationListener implements LocationListener 

    { 

     @Override 
     public void onLocationChanged (Location loc) 

     { 

      loc.getLatitude(); 

      loc.getLongitude(); 

      String Text = "My current location is: " + "Latitud = " + loc.getLatitude() + "Longitud = " + loc.getLongitude(); 

      Toast.makeText (getApplicationContext(), Text, Toast.LENGTH_SHORT).show(); 

     } 

     @Override 
     public void onProviderDisabled (String provider) 

     { 

      Toast.makeText (getApplicationContext(), "Gps Disabled", Toast.LENGTH_SHORT).show(); 

     } 

     @Override 
     public void onProviderEnabled (String provider) 

     { 

      Toast.makeText (getApplicationContext(), "Gps Enabled", Toast.LENGTH_SHORT).show(); 

     } 

     @Override 
     public void onStatusChanged (String provider, int status, Bundle extras) 

     { 

     } 

    }/* End of Class MyLocationListener */ 

}/* End of UseGps Activity */ 
+0

권한을 추가 했습니까? –

+0

예. 여전히 변화가 없다. – User16

+0

에 매니페스트를 표시하십시오. –

답변

0

올바르게 보입니다. 권한을 추가하는 것을 잊지 않았다면 아마 장치가 위성을 찾을 수 없습니다. 건물 밖에서 테스트 해보십시오. 또는 단지는

편집을 사용하려고 : 대신 LocationManager.GPS_PROVIDER의

mlocManager.requestLocationUpdates(mlocManager.getBestProvider(new Criteria(), true), 0, 0, mlocListener); 

합니다.

+0

은 오류를 표시합니다. 기준 및 활성화 만 변수로 해결할 수 없습니다. 비록 내가 집에 가서 시도도 아무 변화가 없었다. – User16

+0

Google지도가 내 위치에서 잘 작동하는 이유는 무엇입니까? 둘 다 GPS 의식을 사용합니까? – User16

+0

업데이트 된 답변을 참조하십시오. – Corver