2

我正在从 lat long 项目中添加简单的 NMEA,Lat long 工作得很好,但是当转移到 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();
    }

  }

}
4

1 回答 1

0

您并没有真正提供有关“错误”的足够信息,但在我看来,以下行将导致编译时错误...

locationManager.addNmeaListener(this);

尝试将其更改为...

locationManager.addNmeaListener(new MyLocationListener());
于 2012-10-16T13:25:25.547 回答