启用GPS设置后如何刷新地图片段? 我正在使用以下代码启用GPS设置。
//ask for runtime permission to showing map
private void askForPermission(String permission, Integer requestCode) {
if (ContextCompat.checkSelfPermission(getActivity(), permission) != PackageManager.PERMISSION_GRANTED) {
// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(getActivity(), permission)) {
ActivityCompat.requestPermissions(getActivity(), new String[]{permission}, requestCode);
//getActivity().finish();
} else {
ActivityCompat.requestPermissions(getActivity(), new String[]{permission}, requestCode);
}
}
}
//check the gps is enable or not
public void statusCheck() {
manager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
buildAlertMessageNoGps();
}
}
//alert dialog to enable location permission
private void buildAlertMessageNoGps() {
final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage("Your GPS seems to be disabled, do you want to enable it?")
.setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog, final int id) {
startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog, final int id) {
dialog.cancel();
}
});
final AlertDialog alert = builder.create();
alert.show();
}
答案 0 :(得分:0)
用于刷新地图。创建一个类似
的方法private void refreshMap(){
if(mMap!=null){
mMap.clear();
}
}
答案 1 :(得分:0)
您必须为此注册广播接收器。检查文档中的gps广播。如果有gps权限,你可以做两次。如果没有权限,你必须在onRequestPrrmissionResult中检查requestpermission方法的结果,然后在那里注册接收器。
P上。 S. Don忘记从广播中取消注册。