0

I am trying to build an android app to scroll over android maps API v2 in android studio. I want to scroll the maps in all different directions using the phone's Accelerometer sensor. For example if the phone is tilted 45 degree to the right, I want the map to be contentiously moving in 45 degree to the right. From what I already found I can only moveCamera (scroll) by latlong target or by pixels, Is there any way to do so using the angle of X , Y coordination? These are samples of what I have tried: 1- Move camera by latlang target.

    CameraPosition cameraPosition = new CameraPosition.Builder()
            .target(MOUNTAIN_VIEW)      // Sets the center of the map to Mountain View
            .zoom(20)                   // Sets the zoom
            .bearing(20)                // Sets the orientation of the camera to east
            .tilt(10)                   // Sets the tilt of the camera to 30 degrees
            .build();                   // Creates a CameraPosition from the builder

    mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition), 1000, null);

2- Find phone angle from X,Y using Accelerometer:

        float X = (float)Math.round(event.values[0]);
        float Y= (float)Math.round(event.values[1]);
        float angle = (float) (Math.atan2(X, Y)/(Math.PI/180));

I would appreciate any new idea to do this or a way to moveCamera by angle.

4
  • What does "contentiously moving in 45 degree to the right" mean? You mean 45 degrees per second? How do you translate the tilt amplitude of the phone (degrees) to a speed in moving the camera? Commented Mar 15, 2017 at 21:47
  • @MehmetKologlu When I change the phone's angle, I can use onSensorChanged method to contentiously scroll the camera on the same direction as the phone. My biggest problem is wheneven I want to use animateCamera of moveCamera, I still need to put the next target point, whereas in my case there is no specific target. Commented Mar 15, 2017 at 22:09
  • Use animateCamera and animate the camera to a point that is (degrees times a constant) off the center of the current view. Do this animation while a case like 'deviceTilted == true' Commented Mar 15, 2017 at 22:15
  • @MehmetKologlu I would appreciate a simple example from you, because honestly I didn't get what you mean. Commented Mar 15, 2017 at 22:25

1 Answer 1

1

This method will just move the camera by pixels equal to the magnitude of the device tilt, over one second.

mMap.animateCamera(CameraUpdateFactory.scrollBy(x, y), 1000, null);
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks mate, I tried it manually and worked, Now I have to adjust it with the sensor and wait to get maps loaded before moving.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.