GPS定位开发步骤以及流程图
目录
GPS定位开发步骤
1. 权限
2.代码流程
2.1. 获取LocationManager
2.2. 判断是否支持GPS
2.3. 获取定位权限
2.4. 创建定位监听
2.5. 判断GPS是否打开
2.6. 初始化GPS定位和注册定位监听
2.7. 打开GPS设置界面
3. GPS定位流程图:
GPS定位开发步骤
1. 权限
Android10 需要添加后台定位权限
2.代码流程
2.1. 获取LocationManager
LocationManager locationManager;
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
2.2. 判断是否支持GPS
/**
* 判断是否支持GPS
*
* @param context
* @return
*/
public boolean hasGPSDevice(Context context) {
final LocationManager mgr = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
if (mgr == null)
return false;
final List
if (providers == null)
return false;
return providers.contains(LocationManager.GPS_PROVIDER);
}
@Override
protected void onResume() {
super.onResume();
boolean flag = hasGPSDevice(context);
if (flag) {
requestPermissions();
}
}
2.3. 获取定位权限
private void requestPermissions() {
AndPermission.with(this)