Android getBearing uses the phone compass or GPS coordinates? - android

Can anyone tell me if “getBearing” uses the phone compass (magnetic north) or simply calculates the bearing storing one coordinate where the user has passed and calculate the bearing using the actual coordinate (true north)?
I see from the reference that “bearingTo” uses the coordinates to calculate the phone actual bearing (using true north), but with the “getBearing” I can’t understand how it works and if it uses the compass/magnetic field sensor (magnetic north) or simply de GPS coordinates(true north).
http://developer.android.com/reference/android/location/Location.html
Thanks

bearingTo gives the initial bearing in a great circle course towards user point. This not the direct bearing to user point but shortest over earth. Google great circle and rhumb lines. For most apps it does not matter as its being updated regularly but if compared to magnetic or doing calculations it throws everything.( It did me I use rhumb bearings)
getBearing gives a "direction of horizontal travel" from the last two location (gps) points.

Related

How to Filter Locations Based on A specific location and a direction

I'm trying to implement a small part of AR, The purpose is to filter locations based on My Location and A direction (North by example) :
I know that to know Direction i need to use Sensor type Orientation
Memory Conception
So can someone help ?
Well, you can get the distance and angle to a point by using Location.distanceTo(). So you'd want to loop through all the points, get the distance and bearing. If the object is close enough and the bearing is within the angle you want, then you treat it as a good point and display it. If it isn't, you skip it.

The exact location with the help of GPS in a rectangular coordinate system (android)

In my application I need to calculate the distance between two gps devices.
When using a GPS coordinates (longitude, latitude, altitude) there is a problem:
The height is determined with greater absolute error. You can verify this by calculating the error
phi and tetta (latitude and longitude) on the basis of formulas
x = r*sin(tetta)*cos(phi)
y = r*sin(tetta)*cos(phi)
z = r*cos(tetta)
However, it is obvious that the GPS receiver is at the beginning accepts data in a Cartesian coordinate system (x, y, z), and then translates them
the system of coordinates r, tetta, phi (altitude, latitude, longitude).
How can I get the original coordinates x,y,z? Are there existing methods in the API? Once again, I don't need conversion formulas
from a spherical coordinate system in a rectangular, I need the accuracy of the original data obtained from a GPS receiver. Is it possible?
You are right the GPS receiver internally uses the ECEF Coordinate system, which is cartesian.
But you cannot get that coordinates on a smartphone. See the above link for conversion from WGS84 coordinates you get in the smartphone to ECEF.
But be warned ECEF this is a 3d cartesian, so the direct line between two points will cut through the earth, that is usefull only for flight applications.
For vehicles (cars, ships) normally you should forget the height of an GPS, just calculate the ground distance (2d- cartesian).
Another solution: first do a (lat,lon) to 2-d cartesian conversion with units meter, then add the height as 3d dimension, this then modells a small part of the earth as flat.
It always depends for whoich purpose you need the calculation.
Why is it obvious that the GPS starts with Cartesian coordinates?
In any case, I'm not seeing a way to get the accuracy of a particular element of the location from the API. It is true that altitude tends to be most error prone (and depends on chipset and is above the reference geoid rather than anything physical). You could get some indication of accuracy by recording data for altitude and modelling the variation.

Calculate the direction of an object with geographical coordinates (latitude, longitude)

I have the coordinates of a player and another object. Both are with geographical coordinates (Latitude and longitude). I have also the direction in what the player is facing (compass). How can I calculate the angle to the other object from the player direction? e.g. I want to know if the object is to the right/left of the player and how many degrees.
Thanks a lot!
With a few it depends, the answer is in essence, you want to know about how to do geographic navigation. One of the reasons it depends is that the distances involve as well as the accuracy needed may influence the answer.
For short distances (<10km) you may be able to ignore the curvature of the Earth, and treat it like a two dimensional Cartesian map (latitude / longitude as X-Y). Then you question becomes basic trigonometry.
For larger distances, or improved accuracy, you can either approximate using an spheroid model of the Earth (assume the Earth is a perfect sphere, which it is not) and calculate the Great Circle bearing and distance.
Or you can model the Earth as an ellipsoid, and calculate its geographic navigation.
Two web pages that may help: Details for computing distance using lat/long coordinates and Calculate distance, bearing and more between Latitude/Longitude points.
Note: atan2 and Haversine formula are often useful implementation details.
Small added note: bearing is a synonym for heading or direction in this context.
You need this spherical trig formula: http://williams.best.vwh.net/avform.htm#Crs Once you have the course (angle relative to true north), you can subtract off the compass heading of the direction the player is facing to get the relative heading.
(I don't know if Android automatically compensates for magnetic variation or not, but if not you'll have to account for it too to get the angle right in all areas)
There are tools in the API to do this for you: Location.bearingTo(Location) and GeomagneticSensor will give you the direction from your position to the target - which you can then adjust based off the devices current heading.
If you've already got a MapView running & are lazy, set up a MyLocationOverlay, enableCompass and skip the GeomagneticSensor and let the MapView do it for you.

How to create a compass where the needle always point to a certain GPS position? (in Android)

I would like to write a app in Android where you see a pointer that always point to a certain GPS position. So when you are turning your phone or driving around the pointer will still point to the gps position.
But I have no idea how to do the calculations with the gps position and the compass sensordata.
Can anyone give me some pointers how to get started or maybe have a example of how to do this?
To achieve this you will need to know several things:
Where you want to point to.
Where you are.
What map projection you are using (metres, degrees etc)
Use the android LocationManager and register for position updates. When these updates arrive you need to extract the position and bearing (could also use compass for bearing) and convert them to the map format you are using. Commonly this will be the Google maps spherical Mercator variation.
With this information you can use trigonometry to calculate the angle between you and your tagged location and use this to draw your direction arrow on a map, or with the bearing data to tell you which way to turn.
Same starting point as above answer, but no trigonometry calculation required. Just calls of existing methods.
You have
your actual position from onLocationChanged (method of the Location class)
the coordinates (lat/lon) to point to
You can now
create an overlay on googleMaps, and draw a line from your position to the point to point to.
or if you want a shorter line (or arrow)
"bearingTo()" (again from the Location class)gives you the direction to point to. Draw a line (or arrow) and rotate it to this direction

How to get real north and magnetic north with getOrientation function

How to get real north and magnetic north with getOrientation function?
getOrientation function returns float[3] with bearing, pitch and roll in second parameter...
How I can calculate real north from these values?
Thank you
The first float in your array is what you want to use to figure magnetic north.
For "true" north, you need to use GeomagneticField.getDeclination(). You have to initialize that class with the approximate location (network-provided is sufficient).
I am not sure this is the right answer, but my guess is that you will only be able to get the magnetic north because that's what the compass will give you.
To "calculate" the true north, you will need your (or the phone's) location and then map that to find the right deviation. You could use some online tool or maybe based on maps you can try to have some simple formula to compute it... (can work if you target it to a specific area).
Couple of notes also...
It will not be too precise anyway, you will always have errors introduced by the variation which is caused by the environment of the compass.
The difference between true and magnetic north changes constantly... not very fast, but over a couple of years, you'll definitely have a difference (depends how accurate you want to be)

Categories

Resources