4

When using Google Maps V2 on Android, when I call function:

googleMap.setMyLocationEnabled(true);

It gives the button for the current location on TOP-RIGHT of map. I want to change that button location to left-bottom with my custom theme.

What should I do?

FlipperPA
  • 13,607
  • 4
  • 39
  • 71
kartikag01
  • 1,539
  • 1
  • 18
  • 36

2 Answers2

2
GoogleMap mMap;
mMap.setPadding(int left, int top, int right, int bottom).

From Google Maps Android API:

You can add padding around the edges of the map using the GoogleMap.setPadding() method. The map will continue to fill the entire container, but text and control positioning, map gestures, and camera movements will behave as if it has been placed in a smaller space. This results in the following changes: Camera movements via API calls or button presses (e.g., compass, my location, zoom buttons) will be relative to the padded region. getCameraPosition() will return the center of the padded region. Projection.getVisibleRegion() will return the padded region. UI controls will be offset from the edge of the container by the specified number of pixels.

MorZa
  • 2,215
  • 18
  • 33
0

add this in your onMapReady() method

if (mapView != null &&
            mapView.findViewById(Integer.parseInt("1")) != null) {
        // Get the button view
        View locationButton = ((View) mapView.findViewById(Integer.parseInt("1")).getParent()).findViewById(Integer.parseInt("2"));
        // and next place it, on bottom right (as Google Maps app)
        RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams)
                locationButton.getLayoutParams();
        // position on right bottom above zoomLayout
        View zoom_in_button = mapView.findViewWithTag("GoogleMapZoomInButton");
        View zoom_layout = (View) zoom_in_button.getParent();
        layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP, 0);
        layoutParams.addRule(RelativeLayout.ABOVE, zoom_layout.getId());
        layoutParams.setMargins(0, 0, 30, 30);
    }