Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change Google Map Offset Center

I'm trying to set the user location on the map such that it sits about 1/3 of the way up from the bottom of the screen, and when the map rotates, it will rotate around this point.

The closest I've got to achieving this is by using the setPadding() method, however, this causes the map to sort of shake when rotated, as the center point sort of 'floats' around where it actually should be. It looks quite ugly

int mapHeight = mapView.getHeight();
googleMap.setPadding(0, mapHeight / 5, 0, 0);

Is there a better way to do this?

Edit: Explained in picture below

enter image description here

like image 637
Dportology Avatar asked Jan 23 '17 17:01

Dportology


People also ask

How do you center Google Maps?

Please go to your map and drag and drop your map to the position you wish. You can also zoom in your map a little bit with mouse wheel or zoom cotrols on the bottom right corner of the map. Please remember to save your map after any changes. Hope that helps.

Can you submit a correction to Google Maps?

Remove an incorrect or fraudulent listing Find the place you want to report for review. Close or remove. Choose the reason the place should be removed. Click Submit.


1 Answers

You don't need paddings

Change mappoint X and Y values as you need you can call this where you want! may be inside your onLocationChanged like changeOffsetCenter(location.getLatitude(),location.getLongitude());

 public void changeOffsetCenter(double latitude,double longitude) {
            Point mappoint = mGoogleMap.getProjection().toScreenLocation(new LatLng(latitude, longitude));
            mappoint.set(mappoint.x, mappoint.y-100); // change these values as you need , just hard coded a value if you want you can give it based on a ratio like using DisplayMetrics  as well
            mGoogleMap.animateCamera(CameraUpdateFactory.newLatLng(mGoogleMap.getProjection().fromScreenLocation(mappoint)));
        }

output :

enter image description here

like image 52
Charuක Avatar answered Sep 29 '22 10:09

Charuක