Android 使用地图时的权限请求方法
作者:louyxlovess 时间:2023-08-25 15:02:18
在初始化自己位置的时候请求定位权限:
Constants.ACCESS_FINE_LOCATION_COMMANDS_REQUEST_CODE是自定义的常量值==0x01
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
!= PackageManager.PERMISSION_GRANTED) {
//申请WRITE_EXTERNAL_STORAGE权限
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, Constants.ACCESS_FINE_LOCATION_COMMANDS_REQUEST_CODE);
} else {
/**
* 初始化用户位置
*/
setMyLoctionPicture();
}
/**
* 初始化用户位置
*/
public void setMyLoctionPicture(){
LogUtils.d(TAG,"setMyLocationPicture() is running");
if(aMap==null){
aMap=mapview.getMap();
}
MyLocationStyle locationStyle = new MyLocationStyle();
locationStyle.myLocationIcon(BitmapDescriptorFactory.fromResource(R.mipmap.location_marker));
locationStyle.strokeColor(Color.BLACK);
locationStyle.radiusFillColor(Color.argb(100, 0, 0, 100));
locationStyle.strokeWidth(1.0f);
aMap.setMyLocationStyle(locationStyle);
aMap.setLocationSource(this);
UiSettings uiSettings = aMap.getUiSettings();
uiSettings .setMyLocationButtonEnabled(true);
aMap.setMyLocationEnabled(true);
aMap.setInfoWindowAdapter(this);
aMap.setOnMarkerClickListener(this);
}
这样是确保在Android高版本时定位权限不会被屏蔽;导致定位和导航用不了情况。
来源:https://blog.csdn.net/louyxlovess/article/details/53116414
标签:Android,地图,权限,请求
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Java并发编程系列之LockSupport的用法
2022-04-07 06:48:58
Android仿微信对话列表滑动删除效果
2023-04-15 13:22:30
![](https://img.aspxhome.com/file/2023/3/88713_0s.jpg)
WPF自定义选择年月控件详解
2021-09-05 23:48:34
![](https://img.aspxhome.com/file/2023/7/98187_0s.jpg)
java查找图中两点之间所有路径
2022-10-04 03:08:11
android之listview悬浮topBar效果
2022-12-24 23:29:58
![](https://img.aspxhome.com/file/2023/8/111748_0s.gif)
SpringCloud Zuul过滤器和谷歌Gauva实现限流
2022-08-31 11:59:21
![](https://img.aspxhome.com/file/2023/5/125225_0s.png)
Android 通过Base64上传图片到服务器实现实例
2021-10-09 20:46:53
Java 关于时间复杂度和空间复杂度的深度刨析
2023-11-10 16:07:39
![](https://img.aspxhome.com/file/2023/8/59358_0s.jpg)
C#使用二分查找法判断指定字符的方法
2022-08-02 06:46:30
datatable去掉重复行的方法
2023-09-02 19:59:41
C#网络编程中常用特性介绍
2021-09-03 23:07:51
![](https://img.aspxhome.com/file/2023/5/111255_0s.jpg)
android为ListView每个Item上面的按钮添加事件
2023-12-19 06:06:47
![](https://img.aspxhome.com/file/2023/7/111707_0s.png)
java写入文件的几种方法分享
2023-06-26 15:56:55
C# 匿名方法基础回顾
2023-02-27 13:59:23
![](https://img.aspxhome.com/file/2023/7/116497_0s.png)
详解如何将JAR包发布到Maven中央仓库
2023-02-14 07:26:00
![](https://img.aspxhome.com/file/2023/9/84769_0s.png)
JavaSwing BorderLayout 边界布局的实现代码
2023-04-23 08:03:40
![](https://img.aspxhome.com/file/2023/2/75002_0s.png)
C++实现希尔排序(ShellSort)
2022-03-03 22:29:13
![](https://img.aspxhome.com/file/2023/3/112303_0s.jpg)
在maven工程里运行java main方法
2023-09-18 04:33:20
Mybatis步骤分解实现一个增删改查程序
2021-09-16 01:12:43
![](https://img.aspxhome.com/file/2023/0/65730_0s.png)
Android实现便于批量操作可多选的图片ListView实例
2021-07-17 19:24:54
![](https://img.aspxhome.com/file/2023/6/137946_0s.jpg)