Hi

distanceTo() works perfect, but bearingTo() doesn't works for me.

myLocation.bearingTo(BuildingLocation) gives me 0º if i am facing the
Building and North direction, gives me 90º if i am facing the Building
and East Direction, gives me -180º if i am facing the Building and
South direction.

Then bearingTo doesn't works for me

i need that when the user faces to the direction of the Building
(facing north, facing south, facing east and facing west), a textview
("Building") or a image (the easiest one) must be draw on the screen
pointing the Building position. For this, i need to know if the phone
is facing to the GPS position of the building.


On 26 sep, 22:31, gjs <garyjamessi...@gmail.com> wrote:
> Hi again,
>
> Also Location has bearingTo() & distanceTo() methods
>
> http://developer.android.com/reference/android/location/Location.html...)
>
> try that.
>
> Regards
>
> On Sep 26, 8:57 pm, saex <elpablos...@gmail.com> wrote:
>
>
>
>
>
>
>
> > I have a Augmented Reality App that simply shows the camera view and
> > get's the user GPS position, azimuth, direction, inclination, etc...
> > Also i have stored the GPS position of a famous building of my City.
> > Now i need that when the user faces to the direction of the Building,
> > a textview ("Building") or a image (the easiest one) must be draw on
> > the screen pointing the Building position. For this, i need to know if
> > the phone is facing to the GPS position of the building.
>
> > ¿How can i do it? I readed some accelerometer/compass/gps tutorials
> > but all of them are poorly explained and didn't show me how to do
> > this, for example:http://www.devx.com/wireless/article/42482/1954
> > this tutorial is very poorly explained and it didn't works when i use
> > the code, Also doesn't gives me explanations of how to show a point
> > when u face the object and how to calculate distances
>
> > Good tutorials for doing this, and code examples, are welcome.
>
> > This is the code i have done. Captures user GPS position (`location`),
> > azimuth, direction, inclination, etc... and also have stored the
> > position of the building (`BuildingLat` & `BuildingLon`).
>
> > Help will be apreciated
>
> > The code (CustomCameraView class is a default camera view class, the
> > code for that class is in the tutorial of the link i posted some lines
> > up):
>
> >     public class AugmentedRealitySampleActivity extends Activity {
> >         private CustomCameraView cv=null;
> >         private TextView tv1;
> >         private TextView tv2;
>
> >         public static SensorManager sensorMan;
>
> >         private Location location; //gps
> >         public volatile float inclination; //accelerometer
>
> >         double BuildingLat;
> >         double BuildingLon;
>
> >         private static final int matrix_size = 16;
> >         float[] R = new float[matrix_size];
> >         float[] outR = new float[matrix_size];
> >         float[] I = new float[matrix_size];
> >         float[] values = new float[3];
> >         private float[] mags;
> >         private float[] accels;
> >         private float azimuth;
> >         private float incValue;
>
> >         LocationManager mLocationManager;
> >         MyLocationListener mLocationListener;
>
> >         public void onCreate(Bundle savedInstanceState)
> >         {
> >                    super.onCreate(savedInstanceState);
> >                    cv = new CustomCameraView(this.getApplicationContext());
> >                    FrameLayout rl = new 
> > FrameLayout(this.getApplicationContext());
> >                    LinearLayout ll= new 
> > LinearLayout(this.getApplicationContext());
> >                    ll.setOrientation(LinearLayout.VERTICAL);
>
> >                    setContentView(rl);
> >                    rl.addView(cv);
> >                    rl.addView(ll);
>
> >                    tv1=new TextView(getApplicationContext());
> >                    tv2=new TextView(getApplicationContext());
>
> >                    ll.addView(tv1);
> >                    ll.addView(tv2);
>
> >                    sensorMan = (SensorManager)
> > getSystemService(Context.SENSOR_SERVICE);
> >                    sensorMan.registerListener(SensorListener,
> > sensorMan.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD),
> > SensorManager.SENSOR_DELAY_UI);
> >                sensorMan.registerListener(SensorListener,
> > sensorMan.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
> > SensorManager.SENSOR_DELAY_UI);
>
> >                    mLocationListener = new MyLocationListener();
> >                    mLocationManager =
> > (LocationManager)getSystemService(Context.LOCATION_SERVICE);
>
> > mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
> > 2000, 3, mLocationListener);
>
> >                    //getLatitude(); getLongitude(); bearingTo(); 
> > distanceTo();
> >                    tv1.setText("Test1");
> >                    tv1.setBackgroundColor(Color.BLACK);
> >                    tv2.setText("Test2");
>
> >                    String coordinates2[] = {"39.48333", "-0.36667"};
> >                BuildingLat = Double.parseDouble(coordinates2[0]);
> >                BuildingLon = Double.parseDouble(coordinates2[1]);
> >         }
>
> >         ///////////////////////
> > GPS /////////////////////////////////////////////
> >     private class MyLocationListener implements LocationListener
> >     {
> >         public void onLocationChanged(Location loc) {
> >                 if (loc!=null)
> >                 {
> >                         tv1.setText("Location= " + loc.getLatitude()+"
> > "+loc.getLongitude());
> >                         location=loc; //stores current location
> >                 }
> >                 else
> >                         tv1.setText("null :(");
> >         }
> >         public void onProviderDisabled(String provider) {       }
> >         public void onProviderEnabled(String provider) {       }
> >         public void onStatusChanged(String provider, int status,
> > Bundle extras) {       }
> >     }
>
> >         //////////////////// COMPASS &
> > ACCELEROMETER ////////////////////////////
> >         SensorEventListener SensorListener = new SensorEventListener()
> >         {
> >                 public void onAccuracyChanged(Sensor arg0, int accuracy){ }
> >                 public void onSensorChanged(SensorEvent event)
> >                 {
> >                         if (event.accuracy == 
> > SensorManager.SENSOR_STATUS_UNRELIABLE)
> >                                 return;
> >                         switch (event.sensor.getType())
> >                         {
> >                                 case Sensor.TYPE_MAGNETIC_FIELD:
> >                                         mags = event.values.clone();
> >                                         break;
> >                                 case Sensor.TYPE_ACCELEROMETER:
> >                                         accels = event.values.clone();
> >                                         break;
> >                         }
> >                         if (mags != null && accels != null)
> >                         {
> >                                 SensorManager.getRotationMatrix(R, I, 
> > accels, mags);
> >                                 //Correct if screen is in Landscape
>
> > SensorManager.remapCoordinateSystem(R,SensorManager.AXIS_X,SensorManager.AX 
> > IS_Z,
> > outR);
> >                                 SensorManager.getOrientation(outR, values);
> >                                 incValue=SensorManager.getInclination(I);
> >                                 azimuth = (float) 
> > Math.round((Math.toDegrees(values[0]))*2)/2;
> >                                 //Adjust the range: 0 < range <= 360 (from: 
> > -180 < range <= 180).
> >                                 azimuth = ( azimuth + 360)%360; // 
> > alternative: mAzimuth =
> > mAzimuth>=0 ? mAzimuth : mAzimuth+360;
> >                                 tv2.setText("Azimuth (deg)= " + azimuth);
> >                                 tv2.append("\n Azimuth (rad)= " + 
> > values[0]);
> >                                 inclination=-Math.round((float) 
> > (values[1]*(360/(2*Math.PI))));
> >                                 tv2.append("\n Pitch (rad)= " + values[1]);
> >                                 tv2.append("\n Pitch (deg)= " + 
> > inclination);
> >                                 tv2.append("\n Roll (rad)= " + 
> > (values[2]*(360/(2*Math.PI))));
> >                         }
> >                 }
> >         };
> >     }

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to