单击按钮时请求GPS位置

时间:2016-11-11 01:28:37

标签: android

我想提示用户请求GPS位置,然后获取位置(lat,lng)。

像这样: http://4.bp.blogspot.com/-CC8P9RN7_pk/VPTwYyjt8kI/AAAAAAAABWw/A5cjqZc39hQ/s1600/Location%2BSettings%2BDialog.png

2 个答案:

答案 0 :(得分:0)

我相信Google提供的位置感知培训涵盖了这一点,here

特别是:

答案 1 :(得分:0)

GPS启用提示代码:

public boolean canGetLocation() {
        return this.canGetLocation;
    }

    public void showSettingsAlert(){
        AlertDialog.Builder alertDialog = new AlertDialog.Builder(mContext);

        alertDialog.setTitle("GPS is settings");

        alertDialog.setMessage("GPS is not enabled. Do you want to go to settings menu?");
        alertDialog.setPositiveButton("Settings", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog,int which) {
                Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                mContext.startActivity(intent);
            }
        });
        alertDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();
            }
        });
        alertDialog.show();
    }

您想要的当前位置(如lat,long或google地图)。