Ich habe Probleme, einen Zielort für eine Kompass-App festzulegen. Im Grunde zeigt es auf ein festgelegtes Ziel (statt nach Norden). Ich habe die ganze Mathematik herausgefunden, aber jedes Mal, wenn ich versuche, die Methode destinationObj.setLattudude() oder setLongitutde() zu machen, schließt sich die App Force.Zielort für Android
Die seltsame Sache ist, wenn ich das ZielObj set.Lat/Long in den Standort-Listener setzen, der den GPS-Standort überschreibt, als ob die App nur einen Ort und nicht zwei erkennen kann.
Jede Anleitung bitte.
Danke,
Hier ist mein Code:
import android.app.Activity;
...
public class CompassActivity extends Activity {
LocationManager locationManager;
Location LocationObj, destinationObj;
private SensorEventListener mListener = new SensorEventListener() {
public void onSensorChanged(SensorEvent event) {
if (LocationObj == null) return;
...bearing calculation...
float bearing = LocationObj.bearingTo(destinationObj);
rotateImageView(needle, R.drawable.needle, direction);
}
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
needle = (ImageView)findViewById(R.id.needle);
log = (TextView)findViewById(R.id.log);
lat = (TextView)findViewById(R.id.lat);
**destinationObj.setLatitude(20);
destinationObj.setLongitude(30);**
LocationManager mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
LocationObj = location;
log.setText(Double.toString(location.getLongitude()));
lat.setText(Double.toString(location.getLatitude()));
}
public void onStatusChanged(String provider, int status, Bundle extras) {}
public void onProviderEnabled(String provider) {}
public void onProviderDisabled(String provider) {}
};
mlocManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
mSensorManager = (SensorManager)getSystemService(Context.SENSOR_SERVICE);
mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);
}
private void rotateImageView(ImageView imageView, int drawable, float rotate) {
...image rotation...
}
@Override
protected void onResume()
{
super.onResume();
mSensorManager.registerListener(mListener, mSensor,
SensorManager.SENSOR_DELAY_GAME);
}
@Override
protected void onStop()
{
mSensorManager.unregisterListener(mListener);
super.onStop();
}
}
wow, das war einfach. Vielen Dank! Tatsächlich verwendetes ZielObj = neuer Standort (""). – mgalal