2011-08-16 14 views
0

私はまだアンドロイドのGPS機能をテストしていて、とgetLastKnownLocation()と1つのonLocationChanged()イベントを1つの場所に配信するようEclipseを取得しました。しかし、Telnetインターフェイスのgeo fixコマンドを使用してさらに場所を変更すると、それ以上のイベントコールは発生しません。その理由は何でしょうか?Android GPSの最初の位置変更がonLocationChangedになった理由は?

私の出力は、アプリケーションの起動後に変更を聞き始めたことを意味します(GpsStatus.GPS_EVENT_STARTEDイベントがあります)、位置更新を受信した後、自動的にリッスンを停止します(GpsStatus.GPS_EVENT_STOPPEDイベントがあります)。詳細について

が尋ねると、私のコードを見て:

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    LocationManager l =(LocationManager) getSystemService(Context.LOCATION_SERVICE); 
    List<String> li = l.getAllProviders(); 
    for (Iterator<String> iterator = li.iterator(); iterator.hasNext();) { 
      String string = iterator.next(); 
      Log.i(TAG, string); 
    } 
    if (l.getLastKnownLocation("gps")==null) 
     Log.i(TAG, "null"); 
    else{    
     Log.i(TAG, l.getLastKnownLocation("gps").toString()); 
    } 

    l.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this); 
} 

... 

@Override 
public void onStatusChanged(String arg0, int arg1, Bundle arg2) { 
    String txt = "onStatusChanged:"+arg0+":"; 
    switch(arg1){ 
     case GpsStatus.GPS_EVENT_FIRST_FIX: 
      txt += "first fix"; 
      break; 
     case GpsStatus.GPS_EVENT_SATELLITE_STATUS: 
      txt += "sat status"; 
      break; 
     case GpsStatus.GPS_EVENT_STARTED: 
      txt += "event started"; 
      break; 
     case GpsStatus.GPS_EVENT_STOPPED: 
      txt += "event stopped"; 
    } 
    Log.i(TAG, txt); 
} 

... 

@Override 
public void onLocationChanged(Location arg0) { 
    Log.i(TAG, "onLocationChanged:" +arg0.toString()); 
} 

、ここでマニフェスト:

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
     package="com.mypackage.example.gps" 
     android:versionCode="1" 
     android:versionName="1.0"> 
    <uses-sdk android:minSdkVersion="3" /> 
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission> 

    <application android:icon="@drawable/icon" android:label="@string/app_name"> 
     <activity android:name=".gpsActivity" 
        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> 

答えて

1

1.5バージョンのSDKの回避策がバグレポートに含まれています。

In the emulator, on the Home Screen, press "Menu" -> "Settings" -> "Date & Time" -> Uncheck "Automatic" -> "Select Time Zone", and choose the right time zone (ie, yours). 

詳細は"Manually added location updates stop working in Eclipse"をご参照ください。

1

.. onResumeメソッドでは、このような

をあなたの場所の更新コードを入れてください、

@Override 
    public void onResume() { 
     super.onResume(); 
      locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,1000L,1.0f, this); 
    locationManager.requestLocationUpdates(
      LocationManager.NETWORK_PROVIDER, 1000L, 1.0f, this); 
    locationManager.addGpsStatusListener(this); 

} 

また、ミリ秒単位の時間やフロート単位の距離などのパーツを提供します。

希望すると、これが役立ちます。

この回答が参考になった場合は、他の人に投票してください。

+0

私のコードを少しクリアしてくれてありがとう。しかし、それは問題に取り組まず解決しませんでした。 Btw。あなたがそうするかどうかにかかわらず、人々は役に立った応答をupvoteします。 – erikbwork

+1

gpsアクセス用にマニフェストファイルに与えられたアクセス許可の種類を教えてください。 – user370305

+0

もちろん、上記の質問にマニフェストの内容を追加しました。 – erikbwork

関連する問題