Search code examples
javaandroidgoogle-mapslocation

How to change by default blue round location icon in google map fragment in Android?


The blue round icon of current location that appears on map fragment when we enable setMylocationEnabled(true) is required to be changed in my scenario. How can I achieve that by default a vehicle icon appear instead of blue icon. Thank you.


Solution

  • Try this,works for me

      ImageView btnMyLocation = (ImageView) ((View) mapFragment.getView().findViewById(Integer.parseInt("1")).getParent()).findViewById(Integer.parseInt("2"));
        btnMyLocation.setImageResource(R.drawable.ic_current_location);
    
        RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams)
                btnMyLocation.getLayoutParams();
    
        layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE);
        layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
        layoutParams.setMargins(0, 0, 30, 30);
        btnMyLocation.setLayoutParams(layoutParams);