我们正在温泉UI上构建混合应用程序并使用位置服务。 就像在iOS本机应用程序中一样 如果禁用了位置服务,温泉应用程序应显示弹出窗口,该弹出窗口将重定向到设置>隐私页面。以便用户可以启用位置服务。
我能够检测到GPS是否启用,但我无法重定向到GPS启用页面.有人请帮助我在Android和IOS中重定向设置页面。
代码如下
if (navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(
function( position )
{
init(position);
if (Location_Marker)
{
return;
}
Location_Marker = Add_Marker(position.coords.latitude,position.coords.longitude,"Initial Position");
},
function( error ){
switch(error.code)
{
**case error.PERMISSION_DENIED:**
console.log( "Permission Denied: ", error );
ons.notification.alert({message:'Please Enable GPS'});
break;
**case error.POSITION_UNAVAILABLE:**
console.log( "POSITION_UNAVAILABLE: ", error );
ons.notification.confirm({message:'GPS signals are weak'});
break;
}
console.log( "Something went wrong: ", error );
GeoLocation_Not_Supported();
},
);
}
如果权限被拒绝,我想打开移动设置页面,以便用户可以启用GPS
在 Android 中,你可以这样使用:
Intent intent = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivityForResult(callGPSSettingIntent, 100);
我使用以下代码片段来执行此操作。
LocationManager manager;
private final int REQUEST_CODE = 2;
manager = (LocationManager)getActivity().getSystemService( Context.LOCATION_SERVICE );
if (!manager.isProviderEnabled( LocationManager.GPS_PROVIDER ) ) {
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivityForResult(intent, REQUEST_CODE);
}
在onActivityResult
,如果用户是否启用了GPS,我将完成我的工作
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == REQUEST_CODE){
// do your awesome stuff
}
}