How can I change google map my location default button? I set my location enable and map draw standard image to find location, is it possible to change default image?
With a simple trick, you can replace the my location button with a custom one.
1. Customize the layout of your new button
add a new button to your desired location in layout file of map activity.
2. Set my location enabled in maps api
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
// Enable My Location
mMap.setMyLocationEnabled(true);
/* and DON'T disable the default location button*/
}
3. Hide default button of my location.
//Create field for map button.
private View locationButton;
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
mMap.setMyLocationEnabled(true);
// get your maps fragment
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
// Extract My Location View from maps fragment
locationButton = mapFragment.getView().findViewById(0x2);
// Change the visibility of my location button
if(locationButton != null)
locationButton.setVisibility(View.GONE);
}
4. call click method of my location on your custom button click.
findViewById(R.id.ic_location).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(mMap != null)
{
if(locationButton != null)
locationButton.callOnClick();
}
}
});