【问题标题】:Android google map on click of current location button show alert box if gps not enabled如果未启用 gps,则单击当前位置按钮时的 Android 谷歌地图会显示警报框
【发布时间】:2014-10-11 06:03:00
【问题描述】:

我已经在我的应用中实现了 Google 地图。当我点击当前位置按钮时,如果 Gps 未启用,我想显示警报框。

我尝试了这种方式,我得到了那个按钮的视图。

    SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map);


        View plusMinusButton = fm.getView().findViewById(1);
        View locationButton = fm.getView().findViewById(2);

使用 locationButton 我尝试使用 setOnclickListener 但没有帮助。

当我点击这张图片 时我的要求很简单,如果 gps 未启用,那么我必须显示警告框说 gps 未启用。

【问题讨论】:

    标签: android google-maps gps google-maps-android-api-2


    【解决方案1】:

    这是一个请求,Google 将其添加为一项功能(我认为是 2013 年 8 月)。现在您可以像这样收听位置按钮的点击:

    final Context context = this;
    mMap.setOnMyLocationButtonClickListener(new GoogleMap.OnMyLocationButtonClickListener() {
        @Override
        public boolean onMyLocationButtonClick() {
            LocationManager mgr = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
            if (!mgr.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
                Toast.makeText(context, "GPS is disabled!", Toast.LENGTH_SHORT).show();
            }
            return false;
        }
    });
    

    【讨论】:

    • 但是在位置设置中打开位置之后....仍然该按钮没有带来当前位置....那么我如何向用户显示“gps正在搜索您的位置?”的警报? /跨度>
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-07
    • 2017-08-29
    • 1970-01-01
    • 1970-01-01
    • 2015-07-15
    相关资源
    最近更新 更多