Search code examples
javaandroidhtmlgoogle-mapsandroid-studio

How to change the position of My Location Button in Google Maps using android studio


I am working on google maps, and I need to change position of My Location(current location button). Presently current location button is at top-right side. So please help me how to re-position the current location button on google maps screen. Thanks in advance.

my sample code:

final GoogleMap googleMap = mMapView.getMap();
googleMap.setMyLocationEnabled(true);

Solution

  • you can use this

    View locationButton = ((View) mMapView.findViewById(Integer.parseInt("1")).getParent()).findViewById(Integer.parseInt("2"));
    RelativeLayout.LayoutParams rlp = (RelativeLayout.LayoutParams) locationButton.getLayoutParams();
    // position on right bottom
    rlp.addRule(RelativeLayout.ALIGN_PARENT_TOP, 0);
    rlp.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE);
    rlp.setMargins(0, 180, 180, 0);