0

我们正在 onsen 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

4

2 回答 2

0

我使用以下代码段来执行此操作。

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);
}

如果用户启用了 GPS ,onActivityResult我会做我的工作

  @Override
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if(requestCode == REQUEST_CODE){
           // do your awesome stuff
        }
    }
于 2017-02-08T09:19:12.797 回答
0

在 Android 中,您可以这样使用:

 Intent intent = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
 startActivityForResult(callGPSSettingIntent, 100);
于 2017-02-08T08:58:26.237 回答