在Google Map API V2中禁用MyLocation中的中心按钮

med*_*hys 28 android google-maps

我在网上搜索了很多,但我找不到任何能回答我问题的内容.当我启用MyLocation时

gmap.setMyLocationEnabled(真)

我自动获得一个按钮,将地图置于我当前位置的中心位置.我想删除它,所以我问你该怎么做.我希望你们中的某些人可以帮助我!

joh*_*lis 160

GoogleMap对象上调用以下方法之后:

map.setMyLocationEnabled(true);
map.getUiSettings().setMyLocationButtonEnabled(false);
Run Code Online (Sandbox Code Playgroud)

您应该看到当前位置指示器(蓝色圆圈),但没有控件可以将地图置于该位置的中心位置.

  • 这应该是公认的答案,因为它是100%正在寻找的人和可接受的方式. (12认同)

BBo*_*Doo 10

这是非常简单的答案;

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"
Run Code Online (Sandbox Code Playgroud)

[更新]

如果您要删除地图上的位置按钮,请在代码中搜索以下内容并将其删除;

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());
}
Run Code Online (Sandbox Code Playgroud)