0

hello i want to rotate image view by latitude and longitude suppose i have

lat/LNG: (33.6343541968021,73.06278146803379)

now i want my image-view(needle) point this location how i can do this? i am doing this

 public void onSensorChanged(SensorEvent event) {


                float degree = Math.round(event.values[0]);


        RotateAnimation ra1 = new RotateAnimation(
                currentDegree, 
                -degree,
                Animation.RELATIVE_TO_SELF, 0.5f, 
                Animation.RELATIVE_TO_SELF,
                0.5f);

        // how long the animation will take place
        ra1.setDuration(0);

        // set the animation after the end of the reservation status
        ra1.setFillAfter(true);
        compass_img.startAnimation(ra1);
        currentDegree= -degree;}

i am using orientation sensor

John
  • 15
  • 1
  • 6

1 Answers1

0

Try this way

// Get the image we want to work with from a URL
Bitmap myBitmap = BitmapFactory.decodeStream(downloadImageFromWeb());

// or just load a resource from the res/drawable directory:
Bitmap myBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.android1);

// find the width and height of the screen:
Display d = getWindowManager().getDefaultDisplay();
int x = d.getWidth();
int y = d.getHeight();

// get a reference to the ImageView component that will display the image:
ImageView img1 = (ImageView)findViewById(R.id.img1);

// scale it to fit the screen, x and y swapped because my image is wider than it is tall
Bitmap scaledBitmap = Bitmap.createScaledBitmap(myBitmap, y, x, true);

// create a matrix object
Matrix matrix = new Matrix();
matrix.postRotate(-90); // anti-clockwise by 90 degrees

// create a new bitmap from the original using the matrix to transform the result
Bitmap rotatedBitmap = Bitmap.createBitmap(scaledBitmap , 0, 0, scaledBitmap .getWidth(), scaledBitmap .getHeight(), matrix, true);

// display the rotated bitmap
img1.setImageBitmap(rotatedBitmap);

Check Create our Android Compass and Rotating a Bitmap in Android

Maveňツ
  • 1
  • 12
  • 50
  • 89
  • how i can rotate image by using latitude and longitude? – John Nov 24 '14 at 13:06
  • @John check http://sunil-android.blogspot.in/2013/02/create-our-android-compass.html – Maveňツ Nov 24 '14 at 13:09
  • thank you but my question is different..... i want to point specific location as in Qibla compass apps, in qibla compass app arrow pointing to qibla whatever if we rotate device it points to qibla only that what i need – John Nov 24 '14 at 13:13