0

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

+1

这是你的答案:http://stackoverflow.com/a/33408809/1281180 – Blackkara

+0

的可能的复制HTTP ://stackoverflow.com/questions/3470693/android-get-location-or-prompt-to-enable-location-service-if-disabled – abielita

回答

0

您应该在您的AndroidManifest.xml中添加permission

有关Android权限的一般信息here

请注意Android 6权限机制已更改(it became iOS like)。

1

我明白您的查询 这里是应该在你的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(); 
    }