2012-10-16 38 views
2

我正在從lat long項目中添加簡單的NMEA,Lat很長時間地工作,但是當轉移到nmea時,它給了我錯誤。從Lat長度轉移到NMEA數據包

如果有人能幫助我,我會很感激你。

protected LocationManager locationManager; 
protected Button retrieveLocationButton; 

@Override 
public void onCreate(Bundle savedInstanceState) { 

    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    retrieveLocationButton = (Button) findViewById(R.id.retrieve_location_button); 

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

    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,2000,0,this); 
    locationManager.addNmeaListener(this); 

    retrieveLocationButton.setOnClickListener(new OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      showCurrentLocation(); 
     } 
    });  
}  



protected void showCurrentLocation() { 
     // TODO Auto-generated method stub 

    } 

    @SuppressWarnings("unused") 
    private class MyLocationListener implements NmeaListener { 

    public void onLocationChanged(Location location) { 
     String message = String.copyValueOf(null); 

     locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0,this); 

     boolean isGood = locationManager.addNmeaListener((NmeaListener) this); 

     Toast.makeText(MainActivity.this, message, Toast.LENGTH_LONG).show(); 
    } 

    public void onStatusChanged(String s, int i, Bundle b) { 
     Toast.makeText(MainActivity.this, "Provider status changed", 
       Toast.LENGTH_LONG).show(); 
    } 

    public void onProviderDisabled(String s) { 
     Toast.makeText(MainActivity.this, 
       "Provider disabled by the user. GPS turned off", 
       Toast.LENGTH_LONG).show(); 
    } 

    public void onProviderEnabled(String s) { 
     Toast.makeText(MainActivity.this, 
       "Provider enabled by the user. GPS turned on", 
       Toast.LENGTH_LONG).show(); 
    } 

    } 

} 
+0

什麼錯誤?你需要給我們一個跡象,說明我們可以如何幫助 –

+0

每次我在修改nmea之後運行代碼強制關閉, – user1749938

回答

0

你真的不提供足夠的信息有關的「錯誤」,但在我看來,下面一行將導致編譯時錯誤...

locationManager.addNmeaListener(this); 

試着改變它..

locationManager.addNmeaListener(new MyLocationListener()); 
+0

其實我每次運行代碼強制關閉, – user1749938

+0

我已經更改爲下面但相同問題的應用程序開始關閉 LocationManager locationmanager; locationManager =(LocationManager)getSystemService(LOCATION_SERVICE); locationManager.addNmeaListener(新NmeaListener(){ \t公共無效onNmeaReceived(長時間戳,字符串NMEA){ Log.d(TAG, 「接收到的NMEA:」); Log.d(TAG, 「時間戳是:」 + timestamp +「nmea is:」+ nmea); }}); – user1749938