【发布时间】:2016-08-09 10:56:41
【问题描述】:
我有一个应用程序,当我们单击一个按钮时,该应用程序会启动带有搜索查询的谷歌地图。但我需要打开位置以提供准确的结果。有可能吗?
【问题讨论】:
标签: android google-maps geolocation google-maps-android-api-2
我有一个应用程序,当我们单击一个按钮时,该应用程序会启动带有搜索查询的谷歌地图。但我需要打开位置以提供准确的结果。有可能吗?
【问题讨论】:
标签: 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();
}
【讨论】:
您应该在 AndroidManifest.xml 中添加 permission。
关于 Android 权限的一般信息here。
注意 Android 6 权限机制已更改 (it became iOS like)。
【讨论】: