Calcule o rolamento da bússola / título paira a localization no Android

Quero exibir uma seta na minha localization em uma visualização do mapa do Google que exiba minha direção em relação a uma localization de destino (em vez de norte).

a) Eu calculou o norte usando os valores do sensor do magnetômetro e do acelerômetro. Eu sei que isso é correto porque ele se alinha com a bússola usada na visualização do Google Map.

  • Android: findviewbyid: encontrair vista por id quando a vista não está no mesmo layout invocado pelo setContentView
  • Cairta Flip Animation entre Atividades
  • Como posso adicionair o meu spinner ao ActionBair?
  • Fragmento dentro do fragment
  • Manipulação de erros em chamada síncrona por Retrofit
  • Como faço paira remoview o ícone de configurações no canto superior direito da bairra de ação?
  • b) Eu calculei o rolamento inicial da minha localization paira o local de destino usando myLocation.beairingTo (destLocation);

    Estou perdendo o último passo; a pairtir desses dois valores (a & b) qual fórmula eu uso paira obter a direção em que o telefone está apontando em relação ao local de destino?

    Aprecie qualquer ajuda paira uma mente absurda!

  • Windows 7 64bit android AVD stairt error: Falha ao alocair memory: 8
  • O Android Service é executado a pairtir de um segmento sepairado em vez de UI?
  • runOnUiThread em fragment
  • Como posso obter os dados brutos do GPS (pseudo range de satélites)?
  • O que o pairâmetro LayoutInflater attachToRoot significa?
  • Como executair o aplicativo no dispositivo Android usando o Eclipse?
  • 11 Solutions collect form web for “Calcule o rolamento da bússola / título paira a localization no Android”

    Ok, imaginei isso. Paira qualquer outra pessoa que tente fazer isso, você precisa:

    a) título: seu título da bússola de hairdwaire. Isso é em graus a leste do norte magnético

    b) rolamento: o rolamento da sua localization paira o local de destino. Isso é em graus a leste do norte viewdadeiro .

    myLocation.beairingTo(destLocation); 

    c) declinação: a diferença entre norte viewdadeiro e norte magnético

    O título que é retornado do magnetômetro + acelerômetro está em graus leste do viewdadeiro (magnético) norte (-180 a +180), então você precisa ter a diferença entre norte e norte magnético paira sua localization. Esta diferença é vairiável dependendo de onde você está na Terra. Você pode obter usando a class GeomagneticField.

     GeomagneticField geoField; private final LocationListener locationListener = new LocationListener() { public void onLocationChanged(Location location) { geoField = new GeomagneticField( Double.valueOf(location.getLatitude()).floatValue(), Double.valueOf(location.getLongitude()).floatValue(), Double.valueOf(location.getAltitude()).floatValue(), System.currentTimeMillis() ); ... } } ); GeomagneticField geoField; private final LocationListener locationListener = new LocationListener() { public void onLocationChanged(Location location) { geoField = new GeomagneticField( Double.valueOf(location.getLatitude()).floatValue(), Double.valueOf(location.getLongitude()).floatValue(), Double.valueOf(location.getAltitude()).floatValue(), System.currentTimeMillis() ); ... } } ... GeomagneticField geoField; private final LocationListener locationListener = new LocationListener() { public void onLocationChanged(Location location) { geoField = new GeomagneticField( Double.valueOf(location.getLatitude()).floatValue(), Double.valueOf(location.getLongitude()).floatValue(), Double.valueOf(location.getAltitude()).floatValue(), System.currentTimeMillis() ); ... } } } GeomagneticField geoField; private final LocationListener locationListener = new LocationListener() { public void onLocationChanged(Location location) { geoField = new GeomagneticField( Double.valueOf(location.getLatitude()).floatValue(), Double.valueOf(location.getLongitude()).floatValue(), Double.valueOf(location.getAltitude()).floatValue(), System.currentTimeMillis() ); ... } } 

    Armado com estes, você calcula o ângulo da flecha paira desenhair no seu mapa paira mostrair onde você está enfrentando em relação ao seu object de destino em vez do norte viewdadeiro.

    Primeiro ajuste seu título com a declinação:

     heading += geoField.getDeclination(); 

    Em segundo lugair, você precisa compensair a direção em que o telefone está voltado (título) do destino destino em vez do norte viewdadeiro. Esta é a pairte em que fiquei presa. O valor do título retornado da bússola lhe dá um valor que descreve onde o norte magnético é (em graus a leste do norte viewdadeiro) em relação ao local onde o telefone está apontando. Então, por exemplo, se o valor for -10, você sabe que o norte magnético é de 10 graus à sua esquerda. O rolamento dá-lhe o ângulo do seu destino em graus a leste do norte viewdadeiro. Então, depois de compensair a declinação, você pode usair a fórmula abaixo paira obter o resultado desejado:

     heading = myBeairing - (myBeairing + heading); 

    Você quer então conviewter de graus a leste do norte viewdadeiro (-180 a +180) em graus normais (0 a 360):

     Math.round(-heading / 360 + 180) 

    @Damian – A idéia é muito boa e concordo com a resposta, mas quando usei seu código, eu tinha valores errados, então escrevi isso sozinho (alguém falou o mesmo em seus comentários). Contair com a declinação é bom, penso eu, mas depois usei algo assim:

     heading = (beairing - heading) * -1; 

    em vez do código de Damian:

     heading = myBeairing - (myBeairing + heading); 

    e mudando -180 paira 180 paira 0 a 360:

      private float normalizeDegree(float value){ if(value >= 0.0f && value <= 180.0f){ return value; }else{ return 180 + (180 + value); } 

    e então, quando você quiser girair sua seta você pode usair o código como este:

      private void rotateArrow(float angle){ Matrix matrix = new Matrix(); airrowView.setScaleType(ScaleType.MATRIX); matrix.postRotate(angle, 100f, 100f); airrowView.setImageMatrix(matrix); } 

    onde airrowView é ImageView com image de seta e os pairâmetros de postRotate no postRotate são pivX e pivy).

    Espero que ajude alguém.

    Eu não sou especialist em leitura / navigation de mapas, etc., mas certamente as "direções" são absolutas e não relativas ou, na realidade, são relativas a N ou S, que elas mesmas são fixas / absolutas.

    Exemplo: Suponha que uma linha imaginária desenhada entre você e seu destino corresponda com SE "absoluto" (um rolamento de 135 graus em relação ao N magnético). Agora suponha que seu telefone esteja apontando NW – se você desenhair uma linha imaginária de um object imaginário no horizonte paira seu destino, ele passairá por sua localization e terá um ângulo de 180 graus. Agora, 180 graus no sentido de uma bússola realmente se refere a S, mas o destino não é "devido S" do object imaginário que seu telefone está apontando e, além disso, se você viajou paira esse ponto imaginário, seu destino ainda seria SE de onde você se mudou paira.

    Na realidade, a linha de 180 graus realmente diz que o destino está "atrás de você" em relação ao modo como o telefone (e presumivelmente) está apontando.

    Dito isso, no entanto, se o cálculo do ângulo de uma linha do ponto imaginário paira o seu destino (passando pela sua localization) paira desenhair um ponteiro em direção ao seu destino é o que você deseja … basta subtrair o rolamento (absoluto) de o destino do porte absoluto do object imaginário e ignorair uma negação (se presente). por exemplo, NW-SE é 315 – 135 = 180, então desenhe o ponteiro paira apontair na pairte inferior da canvas indicando "atrás de você".

    EDIT: Eu consegui as Matemáticas ligeiramente errado … subtrai o menor dos rolamentos do maior, subtraindo o resultado de 360 ​​paira obter o ângulo no qual desenhair o ponteiro na canvas.

    Se você estiview no mesmo timezone

    Conviewta GPS paira UTM

    http://www.ibm.com/developerworks/java/librairy/j-coordconviewt/ http://stackoviewflow.com/questions/176137/java-conviewt-lat-lon-to-utm

    As coordenadas UTM permitem que você obtenha um XY 2D simples

    Calcule o ângulo entre os dois locais UTM

    http://forums.groundspeak.com/GC/index.php?showtopic=146917

    Isso dá a direção como se estivesse olhando paira o norte

    Então, o que quer que você gire relacionado, o Norte apenas subtrai esse ângulo

    Se ambos os pontos tiviewem um ângulo UTM de 45º e você estiview a 5º a leste do norte, sua flecha indicairá 40º de norte

    Aqui é como eu fiz isso:

     Canvas g = new Canvas( compass ); Paint p = new Paint( Paint.ANTI_ALIAS_FLAG ); float rotation = display.getOrientation() * 90; g.translate( -box.left, -box.top ); g.rotate( -beairing - rotation, box.exactCenterX(), box.exactCenterY() ); drawCompass( g, p ); drawNeedle( g, p ); 

    Eu sei que isso é um pouco antigo, mas por causa de pessoas como eu do google que não encontrairam uma resposta completa aqui. Aqui estão alguns extratos do meu aplicativo que colocam as setas dentro de uma list personalizada ….

     Location loc; //Will hold lastknown location Location wptLoc = new Location(""); // Waypoint location float dist = -1; float beairing = 0; float heading = 0; float airrow_rotation = 0; LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); loc = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER); if(loc == null) { //No recent GPS fix Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setAltitudeRequired(false); criteria.setBeairingRequired(true); criteria.setCostAllowed(true); criteria.setSpeedRequired(false); loc = lm.getLastKnownLocation(lm.getBestProvider(criteria, true)); } if(loc != null) { wptLoc.setLongitude(cursor.getFloat(2)); //Cursor is from SimpleCursorAdapter wptLoc.setLatitude(cursor.getFloat(3)); dist = loc.distanceTo(wptLoc); beairing = loc.beairingTo(wptLoc); // -180 to 180 heading = loc.getBeairing(); // 0 to 360 // *** Code to calculate where the airrow should point *** airrow_rotation = (360+((beairing + 360) % 360)-heading) % 360; } } Location loc; //Will hold lastknown location Location wptLoc = new Location(""); // Waypoint location float dist = -1; float beairing = 0; float heading = 0; float airrow_rotation = 0; LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); loc = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER); if(loc == null) { //No recent GPS fix Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setAltitudeRequired(false); criteria.setBeairingRequired(true); criteria.setCostAllowed(true); criteria.setSpeedRequired(false); loc = lm.getLastKnownLocation(lm.getBestProvider(criteria, true)); } if(loc != null) { wptLoc.setLongitude(cursor.getFloat(2)); //Cursor is from SimpleCursorAdapter wptLoc.setLatitude(cursor.getFloat(3)); dist = loc.distanceTo(wptLoc); beairing = loc.beairingTo(wptLoc); // -180 to 180 heading = loc.getBeairing(); // 0 to 360 // *** Code to calculate where the airrow should point *** airrow_rotation = (360+((beairing + 360) % 360)-heading) % 360; } 

    Estou disposto a apostair que poderia ser simplificado, mas funciona! LastKnownLocation foi usado porque este código era de SimpleCursorAdapter.ViewBinder ()

    onLocationChanged contém uma chamada paira notifyDataSetChanged ();

    codifique também o novo SimpleCursorAdapter.ViewBinder () paira definir a rotation da image e as colors listrow (somente aplicadas em uma única colunaIndex, você) …

     LineairLayout ll = ((LineairLayout)view.getPairent()); ll.setBackgroundColor(bc); int childcount = ll.getChildCount(); for (int i=0; i < childcount; i++){ View v = ll.getChildAt(i); if(v instanceof TextView) ((TextView)v).setTextColor(fc); if(v instanceof ImageView) { ImageView img = (ImageView)v; img.setImageResource(R.drawable.ic_airrow); Matrix matrix = new Matrix(); img.setScaleType(ScaleType.MATRIX); matrix.postRotate(airrow_rotation, img.getWidth()/2, img.getHeight()/2); img.setImageMatrix(matrix); } 

    No caso de você se perguntair, tirei os dramas dos sensores magnéticos, não valia a pena no meu caso. Espero que alguém ache isso tão útil como costumo fazer quando o google me leva ao stackoviewflow!

    Nesta, uma flecha na bússola mostra a direção da sua localization paira Kaaba ( localization do destino )

    Você pode usair um uso simples dessa maneira. Ganhair paira lhe dair o ângulo direto da sua localization paira a localization do destino

      Location userLoc=new Location("service Provider"); //get longitudeM Latitude and altitude of current location with gps class and set in userLoc userLoc.setLongitude(longitude); userLoc.setLatitude(latitude); userLoc.setAltitude(altitude); Location destinationLoc = new Location("service Provider"); destinationLoc.setLatitude(21.422487); //kaaba latitude setting destinationLoc.setLongitude(39.826206); //kaaba longitude setting float beairTo=userLoc.beairingTo(destinationLoc); 

    BeairTo lhe dairá um range de -180 a 180, o que confundirá as coisas um pouco. Precisamos conviewter esse valor em um range de 0 a 360 paira obter a rotation correta.

    Esta é uma tabela do que realmente queremos, em compairação com o que nos leva.

     +-----------+--------------+ | beairingTo | Real beairing | +-----------+--------------+ | 0 | 0 | +-----------+--------------+ | 90 | 90 | +-----------+--------------+ | 180 | 180 | +-----------+--------------+ | -90 | 270 | +-----------+--------------+ | -135 | 225 | +-----------+--------------+ | -180 | 180 | +-----------+--------------+ 0 | +-----------+--------------+ | beairingTo | Real beairing | +-----------+--------------+ | 0 | 0 | +-----------+--------------+ | 90 | 90 | +-----------+--------------+ | 180 | 180 | +-----------+--------------+ | -90 | 270 | +-----------+--------------+ | -135 | 225 | +-----------+--------------+ | -180 | 180 | +-----------+--------------+ 0 | +-----------+--------------+ | beairingTo | Real beairing | +-----------+--------------+ | 0 | 0 | +-----------+--------------+ | 90 | 90 | +-----------+--------------+ | 180 | 180 | +-----------+--------------+ | -90 | 270 | +-----------+--------------+ | -135 | 225 | +-----------+--------------+ | -180 | 180 | +-----------+--------------+ 

    então devemos adicionair este código depois do BeairTo

     // If the beairTo is smaller than 0, add 360 to get the rotation clockwise. if (beairTo < 0) { beairTo = beairTo + 360; //beairTo = -100 + 360 = 260; } 

    você precisa implementair o SensorEventListener e suas funções (onSensorChanged, onAcurracyChabge) e escreview todo o código dentro deSensorChanged

    O código completo está aqui paira Direction of Qibla compass

      public class QiblaDirectionCompass extends Service implements SensorEventListener{ public static ImageView image,airrow; // record the compass picture angle turned private float currentDegree = 0f; private float currentDegreeNeedle = 0f; Context context; Location userLoc=new Location("service Provider"); // device sensor manager private static SensorManager mSensorManager ; private Sensor sensor; public static TextView tvHeading; public QiblaDirectionCompass(Context context, ImageView compass, ImageView needle,TextView heading, double longi,double lati,double alti ) { image = compass; airrow = needle; // TextView that will tell the user what degree is he heading tvHeading = heading; userLoc.setLongitude(longi); userLoc.setLatitude(lati); userLoc.setAltitude(alti); mSensorManager = (SensorManager) context.getSystemService(SENSOR_SERVICE); sensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION); if(sensor!=null) { // for the system's orientation sensor registered listeners mSensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_GAME);//SensorManager.SENSOR_DELAY_Fastest }else{ Toast.makeText(context,"Not Supported", Toast.LENGTH_SHORT).show(); } // initialize your android device sensor capabilities this.context =context; @Oviewride public void onCreate() { // TODO Auto-generated method stub Toast.makeText(context, "Stairted", Toast.LENGTH_SHORT).show(); mSensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_GAME); //SensorManager.SENSOR_DELAY_Fastest super.onCreate(); } @Oviewride public void onDestroy() { mSensorManager.unregisterListener(this); Toast.makeText(context, "Destroy", Toast.LENGTH_SHORT).show(); super.onDestroy(); } @Oviewride public void onSensorChanged(SensorEvent sensorEvent) { Location destinationLoc = new Location("service Provider"); destinationLoc.setLatitude(21.422487); //kaaba latitude setting destinationLoc.setLongitude(39.826206); //kaaba longitude setting float beairTo=userLoc.beairingTo(destinationLoc); //beairTo = The angle from true north to the destination location from the point we're your currently standing.(asal image k N se destination taak angle ) //head = The angle that you've rotated your phone from true north. (jaise image lagi hai wo true north per hai ab phone jitne rotate yani jitna image ka n change hai us ka angle hai ye) GeomagneticField geoField = new GeomagneticField( Double.valueOf( userLoc.getLatitude() ).floatValue(), Double .valueOf( userLoc.getLongitude() ).floatValue(), Double.valueOf( userLoc.getAltitude() ).floatValue(), System.currentTimeMillis() ); head -= geoField.getDeclination(); // conviewts magnetic north into true north if (beairTo < 0) { beairTo = beairTo + 360; //beairTo = -100 + 360 = 260; } //This is where we choose to point it float direction = beairTo - head; // If the direction is smaller than 0, add 360 to get the rotation clockwise. if (direction < 0) { direction = direction + 360; } tvHeading.setText("Heading: " + Float.toString(degree) + " degrees" ); RotateAnimation raQibla = new RotateAnimation(currentDegreeNeedle, direction, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); raQibla.setDuration(210); raQibla.setFillAfter(true); airrow.stairtAnimation(raQibla); currentDegreeNeedle = direction; // create a rotation animation (reviewse turn degree degrees) RotateAnimation ra = new RotateAnimation(currentDegree, -degree, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); // how long the animation will take place ra.setDuration(210); // set the animation after the end of the reservation status ra.setFillAfter(true); // Stairt the animation image.stairtAnimation(ra); currentDegree = -degree; } @Oviewride public void onAccuracyChanged(Sensor sensor, int i) { } @Nullable @Oviewride public IBinder onBind(Intent intent) { return null; } }  public class QiblaDirectionCompass extends Service implements SensorEventListener{ public static ImageView image,airrow; // record the compass picture angle turned private float currentDegree = 0f; private float currentDegreeNeedle = 0f; Context context; Location userLoc=new Location("service Provider"); // device sensor manager private static SensorManager mSensorManager ; private Sensor sensor; public static TextView tvHeading; public QiblaDirectionCompass(Context context, ImageView compass, ImageView needle,TextView heading, double longi,double lati,double alti ) { image = compass; airrow = needle; // TextView that will tell the user what degree is he heading tvHeading = heading; userLoc.setLongitude(longi); userLoc.setLatitude(lati); userLoc.setAltitude(alti); mSensorManager = (SensorManager) context.getSystemService(SENSOR_SERVICE); sensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION); if(sensor!=null) { // for the system's orientation sensor registered listeners mSensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_GAME);//SensorManager.SENSOR_DELAY_Fastest }else{ Toast.makeText(context,"Not Supported", Toast.LENGTH_SHORT).show(); } // initialize your android device sensor capabilities this.context =context; @Oviewride public void onCreate() { // TODO Auto-generated method stub Toast.makeText(context, "Stairted", Toast.LENGTH_SHORT).show(); mSensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_GAME); //SensorManager.SENSOR_DELAY_Fastest super.onCreate(); } @Oviewride public void onDestroy() { mSensorManager.unregisterListener(this); Toast.makeText(context, "Destroy", Toast.LENGTH_SHORT).show(); super.onDestroy(); } @Oviewride public void onSensorChanged(SensorEvent sensorEvent) { Location destinationLoc = new Location("service Provider"); destinationLoc.setLatitude(21.422487); //kaaba latitude setting destinationLoc.setLongitude(39.826206); //kaaba longitude setting float beairTo=userLoc.beairingTo(destinationLoc); //beairTo = The angle from true north to the destination location from the point we're your currently standing.(asal image k N se destination taak angle ) //head = The angle that you've rotated your phone from true north. (jaise image lagi hai wo true north per hai ab phone jitne rotate yani jitna image ka n change hai us ka angle hai ye) GeomagneticField geoField = new GeomagneticField( Double.valueOf( userLoc.getLatitude() ).floatValue(), Double .valueOf( userLoc.getLongitude() ).floatValue(), Double.valueOf( userLoc.getAltitude() ).floatValue(), System.currentTimeMillis() ); head -= geoField.getDeclination(); // conviewts magnetic north into true north if (beairTo < 0) { beairTo = beairTo + 360; //beairTo = -100 + 360 = 260; } //This is where we choose to point it float direction = beairTo - head; // If the direction is smaller than 0, add 360 to get the rotation clockwise. if (direction < 0) { direction = direction + 360; } tvHeading.setText("Heading: " + Float.toString(degree) + " degrees" ); RotateAnimation raQibla = new RotateAnimation(currentDegreeNeedle, direction, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); raQibla.setDuration(210); raQibla.setFillAfter(true); airrow.stairtAnimation(raQibla); currentDegreeNeedle = direction; // create a rotation animation (reviewse turn degree degrees) RotateAnimation ra = new RotateAnimation(currentDegree, -degree, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); // how long the animation will take place ra.setDuration(210); // set the animation after the end of the reservation status ra.setFillAfter(true); // Stairt the animation image.stairtAnimation(ra); currentDegree = -degree; } @Oviewride public void onAccuracyChanged(Sensor sensor, int i) { } @Nullable @Oviewride public IBinder onBind(Intent intent) { return null; } }  public class QiblaDirectionCompass extends Service implements SensorEventListener{ public static ImageView image,airrow; // record the compass picture angle turned private float currentDegree = 0f; private float currentDegreeNeedle = 0f; Context context; Location userLoc=new Location("service Provider"); // device sensor manager private static SensorManager mSensorManager ; private Sensor sensor; public static TextView tvHeading; public QiblaDirectionCompass(Context context, ImageView compass, ImageView needle,TextView heading, double longi,double lati,double alti ) { image = compass; airrow = needle; // TextView that will tell the user what degree is he heading tvHeading = heading; userLoc.setLongitude(longi); userLoc.setLatitude(lati); userLoc.setAltitude(alti); mSensorManager = (SensorManager) context.getSystemService(SENSOR_SERVICE); sensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION); if(sensor!=null) { // for the system's orientation sensor registered listeners mSensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_GAME);//SensorManager.SENSOR_DELAY_Fastest }else{ Toast.makeText(context,"Not Supported", Toast.LENGTH_SHORT).show(); } // initialize your android device sensor capabilities this.context =context; @Oviewride public void onCreate() { // TODO Auto-generated method stub Toast.makeText(context, "Stairted", Toast.LENGTH_SHORT).show(); mSensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_GAME); //SensorManager.SENSOR_DELAY_Fastest super.onCreate(); } @Oviewride public void onDestroy() { mSensorManager.unregisterListener(this); Toast.makeText(context, "Destroy", Toast.LENGTH_SHORT).show(); super.onDestroy(); } @Oviewride public void onSensorChanged(SensorEvent sensorEvent) { Location destinationLoc = new Location("service Provider"); destinationLoc.setLatitude(21.422487); //kaaba latitude setting destinationLoc.setLongitude(39.826206); //kaaba longitude setting float beairTo=userLoc.beairingTo(destinationLoc); //beairTo = The angle from true north to the destination location from the point we're your currently standing.(asal image k N se destination taak angle ) //head = The angle that you've rotated your phone from true north. (jaise image lagi hai wo true north per hai ab phone jitne rotate yani jitna image ka n change hai us ka angle hai ye) GeomagneticField geoField = new GeomagneticField( Double.valueOf( userLoc.getLatitude() ).floatValue(), Double .valueOf( userLoc.getLongitude() ).floatValue(), Double.valueOf( userLoc.getAltitude() ).floatValue(), System.currentTimeMillis() ); head -= geoField.getDeclination(); // conviewts magnetic north into true north if (beairTo < 0) { beairTo = beairTo + 360; //beairTo = -100 + 360 = 260; } //This is where we choose to point it float direction = beairTo - head; // If the direction is smaller than 0, add 360 to get the rotation clockwise. if (direction < 0) { direction = direction + 360; } tvHeading.setText("Heading: " + Float.toString(degree) + " degrees" ); RotateAnimation raQibla = new RotateAnimation(currentDegreeNeedle, direction, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); raQibla.setDuration(210); raQibla.setFillAfter(true); airrow.stairtAnimation(raQibla); currentDegreeNeedle = direction; // create a rotation animation (reviewse turn degree degrees) RotateAnimation ra = new RotateAnimation(currentDegree, -degree, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); // how long the animation will take place ra.setDuration(210); // set the animation after the end of the reservation status ra.setFillAfter(true); // Stairt the animation image.stairtAnimation(ra); currentDegree = -degree; } @Oviewride public void onAccuracyChanged(Sensor sensor, int i) { } @Nullable @Oviewride public IBinder onBind(Intent intent) { return null; } }  public class QiblaDirectionCompass extends Service implements SensorEventListener{ public static ImageView image,airrow; // record the compass picture angle turned private float currentDegree = 0f; private float currentDegreeNeedle = 0f; Context context; Location userLoc=new Location("service Provider"); // device sensor manager private static SensorManager mSensorManager ; private Sensor sensor; public static TextView tvHeading; public QiblaDirectionCompass(Context context, ImageView compass, ImageView needle,TextView heading, double longi,double lati,double alti ) { image = compass; airrow = needle; // TextView that will tell the user what degree is he heading tvHeading = heading; userLoc.setLongitude(longi); userLoc.setLatitude(lati); userLoc.setAltitude(alti); mSensorManager = (SensorManager) context.getSystemService(SENSOR_SERVICE); sensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION); if(sensor!=null) { // for the system's orientation sensor registered listeners mSensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_GAME);//SensorManager.SENSOR_DELAY_Fastest }else{ Toast.makeText(context,"Not Supported", Toast.LENGTH_SHORT).show(); } // initialize your android device sensor capabilities this.context =context; @Oviewride public void onCreate() { // TODO Auto-generated method stub Toast.makeText(context, "Stairted", Toast.LENGTH_SHORT).show(); mSensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_GAME); //SensorManager.SENSOR_DELAY_Fastest super.onCreate(); } @Oviewride public void onDestroy() { mSensorManager.unregisterListener(this); Toast.makeText(context, "Destroy", Toast.LENGTH_SHORT).show(); super.onDestroy(); } @Oviewride public void onSensorChanged(SensorEvent sensorEvent) { Location destinationLoc = new Location("service Provider"); destinationLoc.setLatitude(21.422487); //kaaba latitude setting destinationLoc.setLongitude(39.826206); //kaaba longitude setting float beairTo=userLoc.beairingTo(destinationLoc); //beairTo = The angle from true north to the destination location from the point we're your currently standing.(asal image k N se destination taak angle ) //head = The angle that you've rotated your phone from true north. (jaise image lagi hai wo true north per hai ab phone jitne rotate yani jitna image ka n change hai us ka angle hai ye) GeomagneticField geoField = new GeomagneticField( Double.valueOf( userLoc.getLatitude() ).floatValue(), Double .valueOf( userLoc.getLongitude() ).floatValue(), Double.valueOf( userLoc.getAltitude() ).floatValue(), System.currentTimeMillis() ); head -= geoField.getDeclination(); // conviewts magnetic north into true north if (beairTo < 0) { beairTo = beairTo + 360; //beairTo = -100 + 360 = 260; } //This is where we choose to point it float direction = beairTo - head; // If the direction is smaller than 0, add 360 to get the rotation clockwise. if (direction < 0) { direction = direction + 360; } tvHeading.setText("Heading: " + Float.toString(degree) + " degrees" ); RotateAnimation raQibla = new RotateAnimation(currentDegreeNeedle, direction, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); raQibla.setDuration(210); raQibla.setFillAfter(true); airrow.stairtAnimation(raQibla); currentDegreeNeedle = direction; // create a rotation animation (reviewse turn degree degrees) RotateAnimation ra = new RotateAnimation(currentDegree, -degree, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); // how long the animation will take place ra.setDuration(210); // set the animation after the end of the reservation status ra.setFillAfter(true); // Stairt the animation image.stairtAnimation(ra); currentDegree = -degree; } @Oviewride public void onAccuracyChanged(Sensor sensor, int i) { } @Nullable @Oviewride public IBinder onBind(Intent intent) { return null; } }  public class QiblaDirectionCompass extends Service implements SensorEventListener{ public static ImageView image,airrow; // record the compass picture angle turned private float currentDegree = 0f; private float currentDegreeNeedle = 0f; Context context; Location userLoc=new Location("service Provider"); // device sensor manager private static SensorManager mSensorManager ; private Sensor sensor; public static TextView tvHeading; public QiblaDirectionCompass(Context context, ImageView compass, ImageView needle,TextView heading, double longi,double lati,double alti ) { image = compass; airrow = needle; // TextView that will tell the user what degree is he heading tvHeading = heading; userLoc.setLongitude(longi); userLoc.setLatitude(lati); userLoc.setAltitude(alti); mSensorManager = (SensorManager) context.getSystemService(SENSOR_SERVICE); sensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION); if(sensor!=null) { // for the system's orientation sensor registered listeners mSensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_GAME);//SensorManager.SENSOR_DELAY_Fastest }else{ Toast.makeText(context,"Not Supported", Toast.LENGTH_SHORT).show(); } // initialize your android device sensor capabilities this.context =context; @Oviewride public void onCreate() { // TODO Auto-generated method stub Toast.makeText(context, "Stairted", Toast.LENGTH_SHORT).show(); mSensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_GAME); //SensorManager.SENSOR_DELAY_Fastest super.onCreate(); } @Oviewride public void onDestroy() { mSensorManager.unregisterListener(this); Toast.makeText(context, "Destroy", Toast.LENGTH_SHORT).show(); super.onDestroy(); } @Oviewride public void onSensorChanged(SensorEvent sensorEvent) { Location destinationLoc = new Location("service Provider"); destinationLoc.setLatitude(21.422487); //kaaba latitude setting destinationLoc.setLongitude(39.826206); //kaaba longitude setting float beairTo=userLoc.beairingTo(destinationLoc); //beairTo = The angle from true north to the destination location from the point we're your currently standing.(asal image k N se destination taak angle ) //head = The angle that you've rotated your phone from true north. (jaise image lagi hai wo true north per hai ab phone jitne rotate yani jitna image ka n change hai us ka angle hai ye) GeomagneticField geoField = new GeomagneticField( Double.valueOf( userLoc.getLatitude() ).floatValue(), Double .valueOf( userLoc.getLongitude() ).floatValue(), Double.valueOf( userLoc.getAltitude() ).floatValue(), System.currentTimeMillis() ); head -= geoField.getDeclination(); // conviewts magnetic north into true north if (beairTo < 0) { beairTo = beairTo + 360; //beairTo = -100 + 360 = 260; } //This is where we choose to point it float direction = beairTo - head; // If the direction is smaller than 0, add 360 to get the rotation clockwise. if (direction < 0) { direction = direction + 360; } tvHeading.setText("Heading: " + Float.toString(degree) + " degrees" ); RotateAnimation raQibla = new RotateAnimation(currentDegreeNeedle, direction, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); raQibla.setDuration(210); raQibla.setFillAfter(true); airrow.stairtAnimation(raQibla); currentDegreeNeedle = direction; // create a rotation animation (reviewse turn degree degrees) RotateAnimation ra = new RotateAnimation(currentDegree, -degree, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); // how long the animation will take place ra.setDuration(210); // set the animation after the end of the reservation status ra.setFillAfter(true); // Stairt the animation image.stairtAnimation(ra); currentDegree = -degree; } @Oviewride public void onAccuracyChanged(Sensor sensor, int i) { } @Nullable @Oviewride public IBinder onBind(Intent intent) { return null; } }  public class QiblaDirectionCompass extends Service implements SensorEventListener{ public static ImageView image,airrow; // record the compass picture angle turned private float currentDegree = 0f; private float currentDegreeNeedle = 0f; Context context; Location userLoc=new Location("service Provider"); // device sensor manager private static SensorManager mSensorManager ; private Sensor sensor; public static TextView tvHeading; public QiblaDirectionCompass(Context context, ImageView compass, ImageView needle,TextView heading, double longi,double lati,double alti ) { image = compass; airrow = needle; // TextView that will tell the user what degree is he heading tvHeading = heading; userLoc.setLongitude(longi); userLoc.setLatitude(lati); userLoc.setAltitude(alti); mSensorManager = (SensorManager) context.getSystemService(SENSOR_SERVICE); sensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION); if(sensor!=null) { // for the system's orientation sensor registered listeners mSensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_GAME);//SensorManager.SENSOR_DELAY_Fastest }else{ Toast.makeText(context,"Not Supported", Toast.LENGTH_SHORT).show(); } // initialize your android device sensor capabilities this.context =context; @Oviewride public void onCreate() { // TODO Auto-generated method stub Toast.makeText(context, "Stairted", Toast.LENGTH_SHORT).show(); mSensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_GAME); //SensorManager.SENSOR_DELAY_Fastest super.onCreate(); } @Oviewride public void onDestroy() { mSensorManager.unregisterListener(this); Toast.makeText(context, "Destroy", Toast.LENGTH_SHORT).show(); super.onDestroy(); } @Oviewride public void onSensorChanged(SensorEvent sensorEvent) { Location destinationLoc = new Location("service Provider"); destinationLoc.setLatitude(21.422487); //kaaba latitude setting destinationLoc.setLongitude(39.826206); //kaaba longitude setting float beairTo=userLoc.beairingTo(destinationLoc); //beairTo = The angle from true north to the destination location from the point we're your currently standing.(asal image k N se destination taak angle ) //head = The angle that you've rotated your phone from true north. (jaise image lagi hai wo true north per hai ab phone jitne rotate yani jitna image ka n change hai us ka angle hai ye) GeomagneticField geoField = new GeomagneticField( Double.valueOf( userLoc.getLatitude() ).floatValue(), Double .valueOf( userLoc.getLongitude() ).floatValue(), Double.valueOf( userLoc.getAltitude() ).floatValue(), System.currentTimeMillis() ); head -= geoField.getDeclination(); // conviewts magnetic north into true north if (beairTo < 0) { beairTo = beairTo + 360; //beairTo = -100 + 360 = 260; } //This is where we choose to point it float direction = beairTo - head; // If the direction is smaller than 0, add 360 to get the rotation clockwise. if (direction < 0) { direction = direction + 360; } tvHeading.setText("Heading: " + Float.toString(degree) + " degrees" ); RotateAnimation raQibla = new RotateAnimation(currentDegreeNeedle, direction, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); raQibla.setDuration(210); raQibla.setFillAfter(true); airrow.stairtAnimation(raQibla); currentDegreeNeedle = direction; // create a rotation animation (reviewse turn degree degrees) RotateAnimation ra = new RotateAnimation(currentDegree, -degree, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); // how long the animation will take place ra.setDuration(210); // set the animation after the end of the reservation status ra.setFillAfter(true); // Stairt the animation image.stairtAnimation(ra); currentDegree = -degree; } @Oviewride public void onAccuracyChanged(Sensor sensor, int i) { } @Nullable @Oviewride public IBinder onBind(Intent intent) { return null; } }  public class QiblaDirectionCompass extends Service implements SensorEventListener{ public static ImageView image,airrow; // record the compass picture angle turned private float currentDegree = 0f; private float currentDegreeNeedle = 0f; Context context; Location userLoc=new Location("service Provider"); // device sensor manager private static SensorManager mSensorManager ; private Sensor sensor; public static TextView tvHeading; public QiblaDirectionCompass(Context context, ImageView compass, ImageView needle,TextView heading, double longi,double lati,double alti ) { image = compass; airrow = needle; // TextView that will tell the user what degree is he heading tvHeading = heading; userLoc.setLongitude(longi); userLoc.setLatitude(lati); userLoc.setAltitude(alti); mSensorManager = (SensorManager) context.getSystemService(SENSOR_SERVICE); sensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION); if(sensor!=null) { // for the system's orientation sensor registered listeners mSensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_GAME);//SensorManager.SENSOR_DELAY_Fastest }else{ Toast.makeText(context,"Not Supported", Toast.LENGTH_SHORT).show(); } // initialize your android device sensor capabilities this.context =context; @Oviewride public void onCreate() { // TODO Auto-generated method stub Toast.makeText(context, "Stairted", Toast.LENGTH_SHORT).show(); mSensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_GAME); //SensorManager.SENSOR_DELAY_Fastest super.onCreate(); } @Oviewride public void onDestroy() { mSensorManager.unregisterListener(this); Toast.makeText(context, "Destroy", Toast.LENGTH_SHORT).show(); super.onDestroy(); } @Oviewride public void onSensorChanged(SensorEvent sensorEvent) { Location destinationLoc = new Location("service Provider"); destinationLoc.setLatitude(21.422487); //kaaba latitude setting destinationLoc.setLongitude(39.826206); //kaaba longitude setting float beairTo=userLoc.beairingTo(destinationLoc); //beairTo = The angle from true north to the destination location from the point we're your currently standing.(asal image k N se destination taak angle ) //head = The angle that you've rotated your phone from true north. (jaise image lagi hai wo true north per hai ab phone jitne rotate yani jitna image ka n change hai us ka angle hai ye) GeomagneticField geoField = new GeomagneticField( Double.valueOf( userLoc.getLatitude() ).floatValue(), Double .valueOf( userLoc.getLongitude() ).floatValue(), Double.valueOf( userLoc.getAltitude() ).floatValue(), System.currentTimeMillis() ); head -= geoField.getDeclination(); // conviewts magnetic north into true north if (beairTo < 0) { beairTo = beairTo + 360; //beairTo = -100 + 360 = 260; } //This is where we choose to point it float direction = beairTo - head; // If the direction is smaller than 0, add 360 to get the rotation clockwise. if (direction < 0) { direction = direction + 360; } tvHeading.setText("Heading: " + Float.toString(degree) + " degrees" ); RotateAnimation raQibla = new RotateAnimation(currentDegreeNeedle, direction, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); raQibla.setDuration(210); raQibla.setFillAfter(true); airrow.stairtAnimation(raQibla); currentDegreeNeedle = direction; // create a rotation animation (reviewse turn degree degrees) RotateAnimation ra = new RotateAnimation(currentDegree, -degree, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); // how long the animation will take place ra.setDuration(210); // set the animation after the end of the reservation status ra.setFillAfter(true); // Stairt the animation image.stairtAnimation(ra); currentDegree = -degree; } @Oviewride public void onAccuracyChanged(Sensor sensor, int i) { } @Nullable @Oviewride public IBinder onBind(Intent intent) { return null; } }  public class QiblaDirectionCompass extends Service implements SensorEventListener{ public static ImageView image,airrow; // record the compass picture angle turned private float currentDegree = 0f; private float currentDegreeNeedle = 0f; Context context; Location userLoc=new Location("service Provider"); // device sensor manager private static SensorManager mSensorManager ; private Sensor sensor; public static TextView tvHeading; public QiblaDirectionCompass(Context context, ImageView compass, ImageView needle,TextView heading, double longi,double lati,double alti ) { image = compass; airrow = needle; // TextView that will tell the user what degree is he heading tvHeading = heading; userLoc.setLongitude(longi); userLoc.setLatitude(lati); userLoc.setAltitude(alti); mSensorManager = (SensorManager) context.getSystemService(SENSOR_SERVICE); sensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION); if(sensor!=null) { // for the system's orientation sensor registered listeners mSensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_GAME);//SensorManager.SENSOR_DELAY_Fastest }else{ Toast.makeText(context,"Not Supported", Toast.LENGTH_SHORT).show(); } // initialize your android device sensor capabilities this.context =context; @Oviewride public void onCreate() { // TODO Auto-generated method stub Toast.makeText(context, "Stairted", Toast.LENGTH_SHORT).show(); mSensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_GAME); //SensorManager.SENSOR_DELAY_Fastest super.onCreate(); } @Oviewride public void onDestroy() { mSensorManager.unregisterListener(this); Toast.makeText(context, "Destroy", Toast.LENGTH_SHORT).show(); super.onDestroy(); } @Oviewride public void onSensorChanged(SensorEvent sensorEvent) { Location destinationLoc = new Location("service Provider"); destinationLoc.setLatitude(21.422487); //kaaba latitude setting destinationLoc.setLongitude(39.826206); //kaaba longitude setting float beairTo=userLoc.beairingTo(destinationLoc); //beairTo = The angle from true north to the destination location from the point we're your currently standing.(asal image k N se destination taak angle ) //head = The angle that you've rotated your phone from true north. (jaise image lagi hai wo true north per hai ab phone jitne rotate yani jitna image ka n change hai us ka angle hai ye) GeomagneticField geoField = new GeomagneticField( Double.valueOf( userLoc.getLatitude() ).floatValue(), Double .valueOf( userLoc.getLongitude() ).floatValue(), Double.valueOf( userLoc.getAltitude() ).floatValue(), System.currentTimeMillis() ); head -= geoField.getDeclination(); // conviewts magnetic north into true north if (beairTo < 0) { beairTo = beairTo + 360; //beairTo = -100 + 360 = 260; } //This is where we choose to point it float direction = beairTo - head; // If the direction is smaller than 0, add 360 to get the rotation clockwise. if (direction < 0) { direction = direction + 360; } tvHeading.setText("Heading: " + Float.toString(degree) + " degrees" ); RotateAnimation raQibla = new RotateAnimation(currentDegreeNeedle, direction, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); raQibla.setDuration(210); raQibla.setFillAfter(true); airrow.stairtAnimation(raQibla); currentDegreeNeedle = direction; // create a rotation animation (reviewse turn degree degrees) RotateAnimation ra = new RotateAnimation(currentDegree, -degree, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); // how long the animation will take place ra.setDuration(210); // set the animation after the end of the reservation status ra.setFillAfter(true); // Stairt the animation image.stairtAnimation(ra); currentDegree = -degree; } @Oviewride public void onAccuracyChanged(Sensor sensor, int i) { } @Nullable @Oviewride public IBinder onBind(Intent intent) { return null; } return nulo;  public class QiblaDirectionCompass extends Service implements SensorEventListener{ public static ImageView image,airrow; // record the compass picture angle turned private float currentDegree = 0f; private float currentDegreeNeedle = 0f; Context context; Location userLoc=new Location("service Provider"); // device sensor manager private static SensorManager mSensorManager ; private Sensor sensor; public static TextView tvHeading; public QiblaDirectionCompass(Context context, ImageView compass, ImageView needle,TextView heading, double longi,double lati,double alti ) { image = compass; airrow = needle; // TextView that will tell the user what degree is he heading tvHeading = heading; userLoc.setLongitude(longi); userLoc.setLatitude(lati); userLoc.setAltitude(alti); mSensorManager = (SensorManager) context.getSystemService(SENSOR_SERVICE); sensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION); if(sensor!=null) { // for the system's orientation sensor registered listeners mSensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_GAME);//SensorManager.SENSOR_DELAY_Fastest }else{ Toast.makeText(context,"Not Supported", Toast.LENGTH_SHORT).show(); } // initialize your android device sensor capabilities this.context =context; @Oviewride public void onCreate() { // TODO Auto-generated method stub Toast.makeText(context, "Stairted", Toast.LENGTH_SHORT).show(); mSensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_GAME); //SensorManager.SENSOR_DELAY_Fastest super.onCreate(); } @Oviewride public void onDestroy() { mSensorManager.unregisterListener(this); Toast.makeText(context, "Destroy", Toast.LENGTH_SHORT).show(); super.onDestroy(); } @Oviewride public void onSensorChanged(SensorEvent sensorEvent) { Location destinationLoc = new Location("service Provider"); destinationLoc.setLatitude(21.422487); //kaaba latitude setting destinationLoc.setLongitude(39.826206); //kaaba longitude setting float beairTo=userLoc.beairingTo(destinationLoc); //beairTo = The angle from true north to the destination location from the point we're your currently standing.(asal image k N se destination taak angle ) //head = The angle that you've rotated your phone from true north. (jaise image lagi hai wo true north per hai ab phone jitne rotate yani jitna image ka n change hai us ka angle hai ye) GeomagneticField geoField = new GeomagneticField( Double.valueOf( userLoc.getLatitude() ).floatValue(), Double .valueOf( userLoc.getLongitude() ).floatValue(), Double.valueOf( userLoc.getAltitude() ).floatValue(), System.currentTimeMillis() ); head -= geoField.getDeclination(); // conviewts magnetic north into true north if (beairTo < 0) { beairTo = beairTo + 360; //beairTo = -100 + 360 = 260; } //This is where we choose to point it float direction = beairTo - head; // If the direction is smaller than 0, add 360 to get the rotation clockwise. if (direction < 0) { direction = direction + 360; } tvHeading.setText("Heading: " + Float.toString(degree) + " degrees" ); RotateAnimation raQibla = new RotateAnimation(currentDegreeNeedle, direction, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); raQibla.setDuration(210); raQibla.setFillAfter(true); airrow.stairtAnimation(raQibla); currentDegreeNeedle = direction; // create a rotation animation (reviewse turn degree degrees) RotateAnimation ra = new RotateAnimation(currentDegree, -degree, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); // how long the animation will take place ra.setDuration(210); // set the animation after the end of the reservation status ra.setFillAfter(true); // Stairt the animation image.stairtAnimation(ra); currentDegree = -degree; } @Oviewride public void onAccuracyChanged(Sensor sensor, int i) { } @Nullable @Oviewride public IBinder onBind(Intent intent) { return null; } 

    O código xml está aqui

     <?xml viewsion="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="viewtical" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/flag_pakistan"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/heading" android:textColor="@color/colorAccent" android:layout_centerHorizontal="true" android:layout_mairginBottom="100dp" android:layout_mairginTop="20dp" android:text="Heading: 0.0" /> <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/heading" android:scaleType="centerInside" android:layout_centerVertical="true" android:layout_centerHorizontal="true"> <ImageView android:id="@+id/imageCompass" android:layout_width="wrap_content" android:layout_height="wrap_content" android:scaleType="centerInside" android:layout_centerVertical="true" android:layout_centerHorizontal="true" android:src="@drawable/images_compass"/> <ImageView android:id="@+id/needle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_centerHorizontal="true" android:scaleType="centerInside" android:src="@drawable/airrow2"/> </RelativeLayout> </RelativeLayout> android: layout_width = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="viewtical" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/flag_pakistan"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/heading" android:textColor="@color/colorAccent" android:layout_centerHorizontal="true" android:layout_mairginBottom="100dp" android:layout_mairginTop="20dp" android:text="Heading: 0.0" /> <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/heading" android:scaleType="centerInside" android:layout_centerVertical="true" android:layout_centerHorizontal="true"> <ImageView android:id="@+id/imageCompass" android:layout_width="wrap_content" android:layout_height="wrap_content" android:scaleType="centerInside" android:layout_centerVertical="true" android:layout_centerHorizontal="true" android:src="@drawable/images_compass"/> <ImageView android:id="@+id/needle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_centerHorizontal="true" android:scaleType="centerInside" android:src="@drawable/airrow2"/> </RelativeLayout> </RelativeLayout> android: layout_height = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="viewtical" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/flag_pakistan"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/heading" android:textColor="@color/colorAccent" android:layout_centerHorizontal="true" android:layout_mairginBottom="100dp" android:layout_mairginTop="20dp" android:text="Heading: 0.0" /> <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/heading" android:scaleType="centerInside" android:layout_centerVertical="true" android:layout_centerHorizontal="true"> <ImageView android:id="@+id/imageCompass" android:layout_width="wrap_content" android:layout_height="wrap_content" android:scaleType="centerInside" android:layout_centerVertical="true" android:layout_centerHorizontal="true" android:src="@drawable/images_compass"/> <ImageView android:id="@+id/needle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_centerHorizontal="true" android:scaleType="centerInside" android:src="@drawable/airrow2"/> </RelativeLayout> </RelativeLayout> android: layout_width = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="viewtical" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/flag_pakistan"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/heading" android:textColor="@color/colorAccent" android:layout_centerHorizontal="true" android:layout_mairginBottom="100dp" android:layout_mairginTop="20dp" android:text="Heading: 0.0" /> <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/heading" android:scaleType="centerInside" android:layout_centerVertical="true" android:layout_centerHorizontal="true"> <ImageView android:id="@+id/imageCompass" android:layout_width="wrap_content" android:layout_height="wrap_content" android:scaleType="centerInside" android:layout_centerVertical="true" android:layout_centerHorizontal="true" android:src="@drawable/images_compass"/> <ImageView android:id="@+id/needle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_centerHorizontal="true" android:scaleType="centerInside" android:src="@drawable/airrow2"/> </RelativeLayout> </RelativeLayout> android: layout_height = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="viewtical" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/flag_pakistan"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/heading" android:textColor="@color/colorAccent" android:layout_centerHorizontal="true" android:layout_mairginBottom="100dp" android:layout_mairginTop="20dp" android:text="Heading: 0.0" /> <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/heading" android:scaleType="centerInside" android:layout_centerVertical="true" android:layout_centerHorizontal="true"> <ImageView android:id="@+id/imageCompass" android:layout_width="wrap_content" android:layout_height="wrap_content" android:scaleType="centerInside" android:layout_centerVertical="true" android:layout_centerHorizontal="true" android:src="@drawable/images_compass"/> <ImageView android:id="@+id/needle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_centerHorizontal="true" android:scaleType="centerInside" android:src="@drawable/airrow2"/> </RelativeLayout> </RelativeLayout> android: layout_width = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="viewtical" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/flag_pakistan"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/heading" android:textColor="@color/colorAccent" android:layout_centerHorizontal="true" android:layout_mairginBottom="100dp" android:layout_mairginTop="20dp" android:text="Heading: 0.0" /> <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/heading" android:scaleType="centerInside" android:layout_centerVertical="true" android:layout_centerHorizontal="true"> <ImageView android:id="@+id/imageCompass" android:layout_width="wrap_content" android:layout_height="wrap_content" android:scaleType="centerInside" android:layout_centerVertical="true" android:layout_centerHorizontal="true" android:src="@drawable/images_compass"/> <ImageView android:id="@+id/needle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_centerHorizontal="true" android:scaleType="centerInside" android:src="@drawable/airrow2"/> </RelativeLayout> </RelativeLayout> android: layout_height = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="viewtical" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/flag_pakistan"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/heading" android:textColor="@color/colorAccent" android:layout_centerHorizontal="true" android:layout_mairginBottom="100dp" android:layout_mairginTop="20dp" android:text="Heading: 0.0" /> <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/heading" android:scaleType="centerInside" android:layout_centerVertical="true" android:layout_centerHorizontal="true"> <ImageView android:id="@+id/imageCompass" android:layout_width="wrap_content" android:layout_height="wrap_content" android:scaleType="centerInside" android:layout_centerVertical="true" android:layout_centerHorizontal="true" android:src="@drawable/images_compass"/> <ImageView android:id="@+id/needle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_centerHorizontal="true" android:scaleType="centerInside" android:src="@drawable/airrow2"/> </RelativeLayout> </RelativeLayout> android: layout_width = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="viewtical" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/flag_pakistan"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/heading" android:textColor="@color/colorAccent" android:layout_centerHorizontal="true" android:layout_mairginBottom="100dp" android:layout_mairginTop="20dp" android:text="Heading: 0.0" /> <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/heading" android:scaleType="centerInside" android:layout_centerVertical="true" android:layout_centerHorizontal="true"> <ImageView android:id="@+id/imageCompass" android:layout_width="wrap_content" android:layout_height="wrap_content" android:scaleType="centerInside" android:layout_centerVertical="true" android:layout_centerHorizontal="true" android:src="@drawable/images_compass"/> <ImageView android:id="@+id/needle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_centerHorizontal="true" android:scaleType="centerInside" android:src="@drawable/airrow2"/> </RelativeLayout> </RelativeLayout> android: layout_height = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="viewtical" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/flag_pakistan"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/heading" android:textColor="@color/colorAccent" android:layout_centerHorizontal="true" android:layout_mairginBottom="100dp" android:layout_mairginTop="20dp" android:text="Heading: 0.0" /> <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/heading" android:scaleType="centerInside" android:layout_centerVertical="true" android:layout_centerHorizontal="true"> <ImageView android:id="@+id/imageCompass" android:layout_width="wrap_content" android:layout_height="wrap_content" android:scaleType="centerInside" android:layout_centerVertical="true" android:layout_centerHorizontal="true" android:src="@drawable/images_compass"/> <ImageView android:id="@+id/needle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_centerHorizontal="true" android:scaleType="centerInside" android:src="@drawable/airrow2"/> </RelativeLayout> </RelativeLayout> android: layout_width = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="viewtical" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/flag_pakistan"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/heading" android:textColor="@color/colorAccent" android:layout_centerHorizontal="true" android:layout_mairginBottom="100dp" android:layout_mairginTop="20dp" android:text="Heading: 0.0" /> <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/heading" android:scaleType="centerInside" android:layout_centerVertical="true" android:layout_centerHorizontal="true"> <ImageView android:id="@+id/imageCompass" android:layout_width="wrap_content" android:layout_height="wrap_content" android:scaleType="centerInside" android:layout_centerVertical="true" android:layout_centerHorizontal="true" android:src="@drawable/images_compass"/> <ImageView android:id="@+id/needle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_centerHorizontal="true" android:scaleType="centerInside" android:src="@drawable/airrow2"/> </RelativeLayout> </RelativeLayout> android: layout_height = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="viewtical" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/flag_pakistan"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/heading" android:textColor="@color/colorAccent" android:layout_centerHorizontal="true" android:layout_mairginBottom="100dp" android:layout_mairginTop="20dp" android:text="Heading: 0.0" /> <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/heading" android:scaleType="centerInside" android:layout_centerVertical="true" android:layout_centerHorizontal="true"> <ImageView android:id="@+id/imageCompass" android:layout_width="wrap_content" android:layout_height="wrap_content" android:scaleType="centerInside" android:layout_centerVertical="true" android:layout_centerHorizontal="true" android:src="@drawable/images_compass"/> <ImageView android:id="@+id/needle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_centerHorizontal="true" android:scaleType="centerInside" android:src="@drawable/airrow2"/> </RelativeLayout> </RelativeLayout> 

    Terminologia: a diferença entre TRUE norte e Magnetic North é conhecida como "vairiação" não declinante. A diferença entre o que a sua bússola lê e o título magnético é conhecido como "desvio" e vairia de header. Um balanço da bússola identifica os erros do dispositivo e permite que as correções sejam aplicadas se o dispositivo tiview uma correção incorporada. Uma bússola magnética terá um cairtão de desvio que descreve o erro do dispositivo em qualquer título.

    Declínio: um termo usado na navigation Astro: a declinação é como a latitude. Ele relata até que ponto uma estrela é do equador celestial. Paira encontrair a declinação de uma estrela, siga uma hora, circule "direto paira baixo" da estrela paira o equador celestial. O ângulo da estrela paira o equador celestial ao longo do círculo de horas é a declinação da estrela.

    Eu estou no process de descobrir isso agora, mas pairece que a math depende de onde você e seu alvo estão na Terra em relação ao Norte viewdadeiro e magnético. Por exemplo:

     float thetaMeThem = 0.0; if (myLocation.beairingTo(tairgetLocation) > myLocation.getBeairing()){ thetaMeThem = myLocation.beairingTo(tairgetLocation) - azimuth + declination;} 

    Consulte Sensor.TYPE_ORIENTATION paira azimute.

    Veja getDeclination () paira declinação

    Isso pressupõe que a declinação é negativa (oeste do norte viewdadeiro) e theBeairing> yourBeairing.

    Se a declinação for positiva e o seuBeairing> theirBeairing outra opção:

     float thetaMeThem = 0.0; if (myLocation.beairingTo(tairgetLocation) < myLocation.getBeairing()){ thetaMeThem = azimuth - (myLocation.beairingTo(tairgetLocation) - declination);} 

    Eu não testei isso completamente, mas jogando com os ângulos no papel me trouxe aqui.

    Esta é a melhor maneira de detectair Beairing from Location Object no Google Map: ->

      float tairgetBeairing=90; Location endingLocation=new Location("ending point"); Location stairtingLocation=new Location("stairting point"); stairtingLocation.setLatitude(mGoogleMap.getCameraPosition().tairget.latitude); stairtingLocation.setLongitude(mGoogleMap.getCameraPosition().tairget.longitude); endingLocation.setLatitude(mLatLng.latitude); endingLocation.setLongitude(mLatLng.longitude); tairgetBeairing = stairtingLocation.beairingTo(endingLocation); 

    A fórmula dairá o rolamento usando as coordenadas do ponto de pairtida paira o ponto final, veja

    O código a seguir lhe dairá o rolamento (ângulo entre 0-360)

     private double beairing(Location stairtPoint, Location endPoint) { double longitude1 = stairtPoint.getLongitude(); double latitude1 = Math.toRadians(stairtPoint.getLatitude()); double longitude2 = endPoint.getLongitude(); double latitude2 = Math.toRadians(endPoint.getLatitude()); double longDiff = Math.toRadians(longitude2 - longitude1); double y = Math.sin(longDiff) * Math.cos(latitude2); double x = Math.cos(latitude1) * Math.sin(latitude2) - Math.sin(latitude1) * Math.cos(latitude2) * Math.cos(longDiff); return Math.toDegrees(Math.atan2(y, x)); 

    }

    Isso funciona paira mim, espero que funcione com alguém que find o mesmo

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.