android - 如何提示用户打开位置?

标签 android google-maps geolocation google-maps-android-api-2

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

最佳答案

我明白你的问题 这是应该添加到您的 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();
    }

关于android - 如何提示用户打开位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36681528/

相关文章:

php - 我如何将我的 Android 设备(不是模拟器)连接到 wamp 服务器?

android - Cordova Android 项目无法通过重复的 google/gms 进行编译

javascript - 如何检查数组对象在 for 循环中是否完成

java - 如何使用图像路径将图像从一个 Activity 传递到另一个 Activity ?

php - android 不处理 JSON 对象

javascript - Google map 标记作为链接

google-maps - 如何使用 Google 路线服务获取具有不同交通方式的多个航点的路线?

javascript - 伊朗的Chrome地理定位

php - 两个地址之间的距离

ios - 收到推送通知时在后台执行代码