Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid Destination Location
    primarykey
    data
    text
    <p>I'm having trouble setting a destination location for a compass app. Basically it points to a set destination (instead of north). I've got all the math figured out, however, whenever I try to do destinationObj.setLatittude() or setLongitutde() the app force closes.</p> <p>The strange thing is if I put the destinationObj set.Lat/Long in the location listener, that overrides the GPS location, as if the app can only recognize one location and not two.</p> <p>Any guidance please.</p> <p>Thanks,</p> <p>Here is my code:</p> <pre><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(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload