Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change position of Google Maps API's "My location" button

I am using the Google Maps Android API v2, and I need a way to chance the position of the "My Location" button.

I get the "My Location" button like this:

GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext()); final GoogleMap map = ((SupportMapFragment) getSupportFragmentManager()         .findFragmentById(R.id.map)).getMap();  // This gets the button map.setMyLocationEnabled(true); 
like image 913
Jakob Avatar asked Jan 23 '13 21:01

Jakob


People also ask

How do I change the position on Google Maps?

Change your home or work addressOpen Google Maps and make sure you're signed in. In the search box, type Home or Work . Next to the address you want to change, click Edit. Type in a new address, then click Save.

Can you customize Google Maps API?

Easily create your styleThe new Google Maps APIs Styling Wizard helps you to create a map style in a few clicks. Use one of our pre-built styles or create your own style from scratch.


1 Answers

You can get the "My Location" button and move it, like :

public class MapFragment extends SupportMapFragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {     View mapView = super.onCreateView(inflater, container, savedInstanceState);         // Get the button view      View locationButton = ((View) mapView.findViewById(1).getParent()).findViewById(2);      // and next place it, for exemple, on bottom right (as Google Maps app)     RelativeLayout.LayoutParams rlp = (RelativeLayout.LayoutParams) locationButton.getLayoutParams();     // position on right bottom     rlp.addRule(RelativeLayout.ALIGN_PARENT_TOP, 0);     rlp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);     rlp.setMargins(0, 0, 30, 30);     } } 
like image 115
fabLouis Avatar answered Sep 23 '22 01:09

fabLouis