31

I searched a lot on the web, but I haven't found anything which answered my question. When I enable MyLocation with

gmap.setMyLocationEnabled(true)

I automatically get a button to center the map on my current location. I want to remove it and so I'm asking you how to do this. I hope somebody of you can help me!

medphys
  • 1,157
  • 3
  • 10
  • 15

3 Answers3

176

After calling the following methods on your GoogleMap object:

map.setMyLocationEnabled(true);
map.getUiSettings().setMyLocationButtonEnabled(false);

you should see the current location indicator (the blue circle), but no control to center the map on that location.

stkent
  • 19,772
  • 14
  • 85
  • 111
john ellis
  • 2,152
  • 2
  • 15
  • 13
  • 12
    This should be the accepted answer since it is 100% what the guy was looking for and the acceptable way to do it. – Deminetix Nov 09 '13 at 10:20
  • When I do this I still get the blue dot or a blue arrow. Disabling the compass does not seem to help. – Andrew S Jul 01 '14 at 23:47
  • 1
    @AndrewS: If you want to disable the blue dot you have to set map.setMyLocationEnabled(false). The code from the answer enables the blue dot, but disables the button. – Apfelsaft Jul 16 '14 at 08:15
  • @Apfelsaft, but then you cannot interact with the location services of Google Maps because the location sublayer has not be initialized. – Andrew S Jul 22 '14 at 14:59
  • This does not take away the blue dot though. Any updates on this? – portfoliobuilder Oct 17 '16 at 00:43
10

It's very simple answer ;

gmap.setMyLocationEnabled(true); ==> means "to center the map on my current location"
gmap.setMyLocationEnabled(false); ==> means "NOT to center the map on my current location"

[update]

If you want to remove your Location Button on your map, search this below in your code and delete it;

public void setMyLocationButtonEnabled(View v) {
    if (!checkReady()) {
        return;
    }
    // Enables/disables the my location button (this DOES NOT enable/disable the my location
    // dot/chevron on the map). The my location button will never appear if the my location
    // layer is not enabled.
    mUiSettings.setMyLocationButtonEnabled(((CheckBox) v).isChecked());
}

public void setMyLocationLayerEnabled(View v) {
    if (!checkReady()) {
        return;
    }
    // Enables/disables the my location layer (i.e., the dot/chevron on the map). If enabled, it
    // will also cause the my location button to show (if it is enabled); if disabled, the my
    // location button will never show.
    mMap.setMyLocationEnabled(((CheckBox) v).isChecked());
}
BBonDoo
  • 766
  • 5
  • 14
2

Have you tried something like this?

<fragment xmlns:map="http://schemas.android.com/apk/res-auto"
        android:id="@+id/backgroundMap"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        map:uiZoomControls="false"
        map:uiCompass="false"
        class="com.google.android.gms.maps.SupportMapFragment"/>

It effectively removes all the default UI off my maps except for the UI related to markers. Check this link for more info.

EDIT

Replying to OP's comment, id advise using a custom location algorithm instead of letting the google maps API take over. I've done it before and its not overly painful, i just put a marker on the map to let the user know where he is, and make the marker draggable so the user can refine his position manually.

Check this link.

Machinarius
  • 3,637
  • 3
  • 30
  • 53
  • It looks very good, but I can't find the exact statement to remove the center button. – medphys Jan 17 '13 at 10:07
  • Any specific reason not to cook up a quick location listener? I know its more work but it pays off in the end. Not judging your decision, just want to see another viewpoint. – Machinarius Jan 17 '13 at 10:22
  • 1
    Because I like the drawable of Google's myLocation and people already know what it is. – medphys Jan 17 '13 at 10:30
  • Im pretty sure that drawable can be used as a bitmap for a marker, a slight amount of reverse engineering on the maps api jar will be needed though. The markers themselves are the iconic inverted droplets – Machinarius Jan 17 '13 at 10:38