2013-02-05 2 views
4

이 소름 끼치는 문제가 있습니다. 내 에뮬레이터의 위치를 ​​얻으려고합니다. 그것은 내 에뮬레이터의 위치를 ​​얻을 때 잘 동작합니다. 하지만 내 위치 좌표를 변경하면 아무 일도 일어나지 않습니다. gps 잘 작동합니다.LocationManager requestLocationUpdates가 작동하지 않습니다.

여기 내 코드입니다

Main.java

import android.app.Activity; 
import android.app.AlertDialog; 
import android.app.AlertDialog.Builder; 
import android.content.DialogInterface; 
import android.content.DialogInterface.OnClickListener; 
import android.content.Intent; 
import android.location.Location; 
import android.location.LocationListener; 
import android.location.LocationManager; 
import android.os.Bundle; 

import android.util.Log; 
import android.view.Menu; 
import android.widget.TextView; 

public class Main extends Activity { 
TextView tvStatus; 
LocationManager lm; 
boolean gpsEnabled; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    tvStatus = (TextView) findViewById(R.id.textView1); 

    lm = (LocationManager) getSystemService(LOCATION_SERVICE); 
    if (lm.isProviderEnabled(LocationManager.GPS_PROVIDER)) { 
     Log.d("", "GPS is Active"); 
     Location l = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER); 
     tvStatus.setText(l.getLatitude()+" , "+l.getLongitude()); 
     lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, 
       new LocationListener() { 

        @Override 
        public void onStatusChanged(String arg0, int arg1, 
          Bundle arg2) { 
         // TODO Auto-generated method stub 

        } 

        @Override 
        public void onProviderEnabled(String arg0) { 
         // TODO Auto-generated method stub 

        } 

        @Override 
        public void onProviderDisabled(String arg0) { 
         // TODO Auto-generated method stub 

        } 

        @Override 
        public void onLocationChanged(Location arg0) { 
         tvStatus.setText("GPS ENABLED: " + gpsEnabled 
           + "\nLatitude: " + arg0.getLatitude() 
           + "\nLongitude: " + arg0.getLongitude()); 
        } 
       }); 
    } 

} 

    } 

Manifest.xml 그것은 에뮬레이터 발생

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.example.enabelinglocationprovider" 
    android:versionCode="1" 
    android:versionName="1.0" > 

    <uses-sdk 
     android:minSdkVersion="5" 
     android:targetSdkVersion="10" /> 
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> 
    <uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION"/> 
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> 
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> 
    <uses-permission android:name="android.permission.INTERNET"/> 

    <application 
     android:allowBackup="true" 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" > 
     <activity 
      android:name="com.example.enabelinglocationprovider.Main" 
      android:label="@string/app_name" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
    </application> 

</manifest> 
+0

위치 관련 서비스가 해당 장치에서 켜져 있습니까? – Pinki

+0

예, GPS가 사용 설정되었습니다. 하나 더. 나는 이클립스에서 내 작업 공간을 전환하고있다. 지금 내 에뮬레이터를 다시 시작하면 제대로 작동합니다. –

+0

i 작업 영역을 전환 할 때 에뮬레이터의 연결이 끊어 졌습니까? –

답변

0

에뮬레이터를 다시 부팅하려고합니다.

은 또는 가까운 모두 일식 및 에뮬레이터 및 시작 모두 다시

3

삼성 폰은이 문제를 가지고있다. 이것에 해킹이 있습니다. 지도 캐시에서 최신 위치를 얻으려면 엉덩이에있는 locationmanager를 걷어차 야합니다.

God.locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, 
      new LocationListener() { 
       @Override 
       public void onStatusChanged(String provider, int status, Bundle extras) { 
       } 

       @Override 
       public void onProviderEnabled(String provider) { 
       } 

       @Override 
       public void onProviderDisabled(String provider) { 
       } 

       @Override 
       public void onLocationChanged(final Location location) { 
       } 
      }); 
    currentLocation = God.locationManager 
      .getLastKnownLocation(LocationManager.NETWORK_PROVIDER); 

전화 getLastKnownLocation 공의와 requestLocationUpdates을 발로 후.

+0

5.1.1 Android 버전의 Nexus 5에서도이 작업을 수행해야했습니다. – gilsaints88

관련 문제