[android-developers] Re: How to know if the phone is facing a given GPS point? (I have the Azimuth of the Phone and his GPS position)

2011-09-26 Thread gjs
Hi,

Just compare the bearing to the building with the current compass
direction.

Regards

On Sep 26, 8:57 pm, saex  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) {       }

[android-developers] Re: How to know if the phone is facing a given GPS point? (I have the Azimuth of the Phone and his GPS position)

2011-09-26 Thread gjs
Hi again,

Also Location has bearingTo() & distanceTo() methods

http://developer.android.com/reference/android/location/Location.html#bearingTo(android.location.Location)

try that.

Regards

On Sep 26, 8:57 pm, saex  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) { 

[android-developers] Re: How to know if the phone is facing a given GPS point? (I have the Azimuth of the Phone and his GPS position)

2011-09-26 Thread lbendlin
Google the interwebs for the formulas for the spherical bearing and distance 
between two geopoints. Then use the GPS heading or the compass heading (the 
latter should be more helpful) and if the heading equals the bearing that 
means you're looking in the direction of the building.

-- 
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

[android-developers] Re: How to know if the phone is facing a given GPS point? (I have the Azimuth of the Phone and his GPS position)

2011-09-27 Thread saex
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  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  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[] = {"

[android-developers] Re: How to know if the phone is facing a given GPS point? (I have the Azimuth of the Phone and his GPS position)

2011-09-27 Thread lbendlin
use the compass heading and compare it with the bearing from your current 
location to the building. Here's the formula in Objective-C but you 
shouldn't have problems to convert this to Java

//spherical bearing between two coordinates
- (CGFloat) sphericalBearingFromLat1:(CGFloat)lat1 Lon1:(CGFloat)lon1 
toLat2:(CGFloat)lat2 Lon2:(CGFloat)lon2 {
lat1 *= 0.0174533; 
lat2 *= 0.0174533;
float dLon = (lon2-lon1) * 0.0174533;
float brng = 57.29578 * atan2(sin(dLon) * cos(lat2), 
  cos(lat1) * sin(lat2) - sin(lat1) * 
cos(lat2) * cos(dLon));
if(brng <= 0.0f) brng += 360.0f;
return brng;
}
 

-- 
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