Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set custom view for my location button in google map

I am using the Google Maps Android API v2, and I need a way to change the view (icon, color, etc.) of "My Location" button.

now i can change the position of that but i need a way to do a full customization. can somebody help me please?

like image 641
MSH Avatar asked Dec 29 '25 21:12

MSH


2 Answers

The location button is actually an ImageView. You should first retrieve the fragment view that is associated with the map:

SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
                                    .findFragmentById(R.id.map);

Next, you should get location view reference from the fragment:

ImageView locationButton = (ImageView) mapFragment.getView().findViewById(2);

Then change it's image to anything you want. e.g.

locationButton.setImageResource(R.drawable.icon_location);

Hope it helps.

like image 199
MLFR2kx Avatar answered Jan 01 '26 11:01

MLFR2kx


I think you can have the "My Location" button view with code below:

View locationButton = ((View) mapView.findViewById(Integer.parseInt("1")).getParent()).findViewById(Integer.parseInt("2"));
like image 26
Mohammad Zarei Avatar answered Jan 01 '26 09:01

Mohammad Zarei



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!