5

I'm developing an app that is using a google map to show your location. I want to rotate the map around the users location. I use getOrientation(R, orientation) (and adjust for true north) to get the device rotation which is working fine but i want the user location to be near the bottom of the screen. I have set the padding on the map to a quarter of the screen height mMap.setPadding(0,screenHeight/4,0,0); What hI have noticed is that the rotation is still done around the point at the centre of the screen NOT the padded centre. This is the code I'm using in onSensorChanged

 currentZoom = mMap.getCameraPosition().zoom;
 CameraPosition currentPlace = new CameraPosition.Builder()
                               .target(new LatLng(currentNode.getLatitude(), currentNode.getLongitude()))
                               .bearing(degrees).tilt(60).zoom(currentZoom).build();
mMap.stopAnimation();
mMap.animateCamera(CameraUpdateFactory.newCameraPosition(currentPlace),40,null);

Is there a way to change the anchor point of camera rotation?

Colm
  • 73
  • 5
  • Try to make your `tilt` as `65.5f` and `zoom` to `18f`, for more details, please refer to [here](http://stackoverflow.com/questions/14767282/android-maps-v2-rotate-mapview-with-compass), [here](http://stackoverflow.com/questions/1830391/rotate-mapview-in-android) and [here](http://stackoverflow.com/questions/26303370/rotate-map-according-current-walk-direction-android-google-maps). – bjiang Feb 23 '15 at 19:00
  • Thanks bjiang, but rotation itself is not the problem, I have setup the orientation and adjusted it for true north and it works fine when I rotate with no padding. The problem is when I add padding to the map the rotation seems to be applied based on the centre of the screen which causes the user location to be shifted causing the whole map to be shifted a few pixels sideways as the map fixes this. – Colm Feb 23 '15 at 20:09
  • Have you solved this problem ? – oshurmamadov Sep 26 '16 at 11:40
  • @oshurmamadov Sorry no, I ended up using Mapzen for the finished project as I couldn't fix this issue. – Colm Sep 27 '16 at 16:00
  • @Colm struggling with it right now – oshurmamadov Sep 28 '16 at 05:12

1 Answers1

0

I was trying to solve this problem for several hours. The only solution I found is not very good, but it works: For example, if you want to move the user 200dp below the center:

1) Set map fragment height to its height + 200dp (Then the map will go 200dp below the screen)

2) This works fine, but it hides Google logo. To preserve the Google logo, set map padding top and bottom to 200dp.

mGoogleMap.setPadding(0, dp2px(200),0 , dp2px(200));

That solves the problem

Grountex
  • 11
  • 1