Home > Article > Web Front-end > How does uniapp determine whether mobile phone positioning is enabled?
The method for uniapp to determine whether mobile phone positioning is enabled: first obtain system information; then determine the platform, the code is [let system = uni.getSystemInfoSync();if (system.platform === 'android')].
The operating environment of this tutorial: windows7 system, uni-app2.5.1 version, Dell G3 computer.
Recommended (free): uni-app development tutorial
uniapp determines whether mobile phone positioning is turned on Method:
/**检查是否打开GPS功能(android)**/ export const checkOpenGPSServiceByAndroid = () => { let system = uni.getSystemInfoSync();// 获取系统信息 if (system.platform === 'android') { // 判断平台 var context = plus.android.importClass("android.content.Context"); var locationManager = plus.android.importClass("android.location.LocationManager"); var main = plus.android.runtimeMainActivity(); var mainSvr = main.getSystemService(context.LOCATION_SERVICE); if (!mainSvr.isProviderEnabled(locationManager.GPS_PROVIDER)) { uni.showModal({ title: '提示', content: '请打开定位服务功能', showCancel: false, // 不显示取消按钮 success() { if (!mainSvr.isProviderEnabled(locationManager.GPS_PROVIDER)) { var Intent = plus.android.importClass('android.content.Intent'); var Settings = plus.android.importClass('android.provider.Settings'); var intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); main.startActivity(intent); // 打开系统设置GPS服务页面 } else { console.log('GPS功能已开启'); } } }); } } }
Related free learning recommendations: Programming Video
The above is the detailed content of How does uniapp determine whether mobile phone positioning is enabled?. For more information, please follow other related articles on the PHP Chinese website!