Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Maps Library V2 zoom controls custom position

How can i customize the position of the builtin zoom controls in a GoogleMap V2 ?

There are a lot of questions related to this topic for the Version 1 of Google Maps library.

Placing Zoom Controls in a MapView

How to reposition built-in zoom controls in MapView?

How to layout zoom Control with setBuiltInZoomControls(true)?

However, i wasn't able to find any questions in relation to the V2 of the library.

In the V2, there's no method

(LinearLayout) mapView.getZoomControls(); 

all the previously mentioned questions becomes obsolete.

Thanks in advance

like image 936
Robert Estivill Avatar asked Dec 28 '12 14:12

Robert Estivill


People also ask

How do I control the zoom on Google Maps?

Google Maps - The Default Controls When showing a standard Google map, it comes with the default control set: Zoom - displays a slider or "+/-" buttons to control the zoom level of the map.

How do I change the zoom level on Google Maps?

Users can zoom the map by clicking the zoom controls. They can also zoom and pan by using two-finger movements on the map for touchscreen devices.

Which method is used to display the controls for zooming options in map in Android?

Important Methods of Zoom ControlsZoomControl zoomControls = (ZoomControls) findViewById(R. id. simpleZoomControl); show(): This method is used to show the zoom controls on the App UI.

Which built in method is used to display zoom controls on Google Maps?

The Maps API provides built-in zoom controls that appear in the bottom right hand corner of the map. These are disabled by default, but can be enabled by calling UiSettings. setZoomControlsEnabled(true) .


2 Answers

Depending on what you're trying to do, you might find GoogleMap.setPadding() useful (added in September 2013).

map.setPadding(leftPadding, topPadding, rightPadding, bottomPadding); 

From the API docs:

This method allows you to define a visible region on the map, to signal to the map that portions of the map around the edges may be obscured, by setting padding on each of the four edges of the map. Map functions will be adapted to the padding. For example, the zoom controls, compass, copyright notices and Google logo will be moved to fit inside the defined region, camera movements will be relative to the center of the visible region, etc.

Also see the description of how padding works in GoogleMap.

like image 173
Mark Doliner Avatar answered Oct 14 '22 04:10

Mark Doliner


Yes, you can change position of ZoomControl and MyLocation button with small hack. In my sample I have SupportMapFragment, which is inflated from xml layout.

View ids for ZoomControl and MyLocation button:

ZoomControl id = 0x1 MyLocation button id = 0x2 

Code to update ZoomControl position:

// Find map fragment SupportMapFragment mapFragment = (SupportMapFragment) getFragmentManager().findFragmentById(R.id.map);  // Find ZoomControl view View zoomControls = mapFragment.getView().findViewById(0x1);  if (zoomControls != null && zoomControls.getLayoutParams() instanceof RelativeLayout.LayoutParams) {     // ZoomControl is inside of RelativeLayout     RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) zoomControls.getLayoutParams();      // Align it to - parent top|left     params.addRule(RelativeLayout.ALIGN_PARENT_TOP);     params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);      // Update margins, set to 10dp     final int margin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10,             getResources().getDisplayMetrics());     params.setMargins(margin, margin, margin, margin); } 
like image 24
vovkab Avatar answered Oct 14 '22 04:10

vovkab