Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/194.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何提示用户打开位置?_Android_Google Maps_Geolocation_Google Maps Android Api 2 - Fatal编程技术网

Android 如何提示用户打开位置?

Android 如何提示用户打开位置?,android,google-maps,geolocation,google-maps-android-api-2,Android,Google Maps,Geolocation,Google Maps Android Api 2,我有一个应用程序,当我们点击一个按钮时,应用程序会启动带有搜索查询的谷歌地图。但我需要打开位置以提供准确的结果。可能吗?您应该添加到您的AndroidManifest.xml中 关于Android权限的一般信息 请注意Android 6权限机制已更改()。我理解您的查询 下面是应该添加到onCreate方法中的代码 LocationManager lm = (LocationManager) getSystemService(LOCATION_SERVICE); if (!lm.isPr

我有一个应用程序,当我们点击一个按钮时,应用程序会启动带有搜索查询的谷歌地图。但我需要打开位置以提供准确的结果。可能吗?

您应该添加到您的AndroidManifest.xml中

关于Android权限的一般信息

请注意Android 6权限机制已更改()。

我理解您的查询 下面是应该添加到onCreate方法中的代码

LocationManager lm = (LocationManager) getSystemService(LOCATION_SERVICE);
    if (!lm.isProviderEnabled(LocationManager.GPS_PROVIDER) ||
            !lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
        // Build the alert dialog
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("Location Services Not Active");
        builder.setMessage("Please enable Location Services and GPS");
        builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialogInterface, int i) {
                // Show location settings when the user acknowledges the alert dialog
                Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                startActivity(intent);
            }
        });
        Dialog alertDialog = builder.create();
        alertDialog.setCanceledOnTouchOutside(false);
        alertDialog.show();
    }
这是你的答案:可能是重复的