【问题标题】:Disable center button in MyLocation at Google Map API V2在 Google Map API V2 的 MyLocation 中禁用中心按钮
【发布时间】:2013-01-17 09:56:35
【问题描述】:

我在网上进行了很多搜索,但没有找到任何可以回答我的问题的内容。 当我使用

启用 MyLocation

gmap.setMyLocationEnabled(true)

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

【问题讨论】:

    标签: android google-maps


    【解决方案1】:

    在您的GoogleMap 对象上调用以下方法后:

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

    您应该会看到当前位置指示器(蓝色圆圈),但无法控制以该位置为中心的地图。

    【讨论】:

    • 这应该是公认的答案,因为它 100% 是这个人正在寻找的,也是可接受的方法。
    • 当我这样做时,我仍然得到蓝点或蓝色箭头。禁用指南针似乎没有帮助。
    • @AndrewS:如果你想禁用蓝点,你必须设置 map.setMyLocationEnabled(false)。答案中的代码启用了蓝点,但禁用了按钮。
    • @Apfelsaft,但是由于位置子层尚未初始化,因此您无法与谷歌地图的位置服务交互。
    • 这并没有消除蓝点。有这方面的更新吗?
    【解决方案2】:

    答案很简单;

    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"
    

    [更新]

    如果您想删除地图上的位置按钮,请在下面的代码中搜索并删除它;

    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());
    }
    

    【讨论】:

    • 我只想禁用该按钮。如果我添加你的声明,我的位置将永远不会显示
    • 不要在你的代码中使用“gmap.setMyLocationEnabled(true)”:删除它。
    • 对不起,我想你不明白我的意思。我想显示当前位置,而不是让地图居中的按钮。
    【解决方案3】:

    你尝试过这样的事情吗?

    <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"/>
    

    它有效地从我的地图上删除了所有默认 UI,除了与标记相关的 UI。 查看this链接了解更多信息。

    编辑

    回复 OP 的评论,id 建议使用自定义位置算法,而不是让谷歌地图 API 接管。我以前做过,而且不是很痛苦,我只是在地图上放了一个标记让用户知道他在哪里,并使标记可拖动,以便用户可以手动调整他的位置。

    检查this 链接。

    【讨论】:

    • 看起来很不错,但是我找不到删除中心按钮的确切说法。
    • 有什么理由不做一个快速定位监听器吗?我知道它需要做更多的工作,但最终会得到回报。不评判你的决定,只是想看看另一个观点。
    • 因为我喜欢 Google 的 myLocation 的可绘制对象,而且人们已经知道它是什么。
    • 我很确定drawable可以用作标记的位图,但需要对maps api jar进行少量逆向工程。标记本身就是标志性的倒水滴
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多