Disable center button in MyLocation at Google Map API V2
Asked Answered
G

3

32

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!

Glori answered 17/1, 2013 at 9:56 Comment(0)
M
177

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.

Messere answered 21/3, 2013 at 13:30 Comment(5)
This should be the accepted answer since it is 100% what the guy was looking for and the acceptable way to do it.Stadium
When I do this I still get the blue dot or a blue arrow. Disabling the compass does not seem to help.Schreck
@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.Sarcous
@Apfelsaft, but then you cannot interact with the location services of Google Maps because the location sublayer has not be initialized.Schreck
This does not take away the blue dot though. Any updates on this?Sphenoid
E
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());
}
Epistasis answered 17/1, 2013 at 10:25 Comment(3)
I only want to disable the button. If I add your statement, my location will never be displayedGlori
NOT USE "gmap.setMyLocationEnabled(true)" in your code: delete it.Epistasis
Sorry, but I think you don't understand me. I want to show the current location, but not the button to center the map.Glori
I
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.

Influenza answered 17/1, 2013 at 9:59 Comment(4)
It looks very good, but I can't find the exact statement to remove the center button.Glori
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.Influenza
Because I like the drawable of Google's myLocation and people already know what it is.Glori
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 dropletsInfluenza

© 2022 - 2024 — McMap. All rights reserved.