2017-02-08 19 views
0

我們正在構建onsen ui和使用位置服務的混合應用程序。與iOS本機應用程序一樣,如果定位服務被禁用,則該溫泉應用程序應顯示彈出窗口,將重定向到設置 - >隱私頁面。以便該用戶可以啓用位置服務。在onsen用戶界面中打開移動GPS啓用設置頁面

我能夠檢測到GPS是否啓用,但我無法重定向到GPS啓用page.someone請幫助我重定向設置頁面在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

+0

安置自己的代碼,以便我們可以幫助 – Akshay

+0

功能(錯誤){ \t \t \t \t \t開關我會盡我的工作(error.code) \t \t \t \t \t { \t \t \t \t \t \t情況error.PERMISSION_DENIED: \t \t \t \t \t \t \t \t的console.log( 「權限被拒絕:」,錯誤); ons.notification.alert({message:'請啓用GPS'}); 休息; \t \t \t \t \t \t情況error.POSITION_UNAVAILABLE: \t \t \t \t \t \t \t \t的console.log( 「POSITION_UNAVAILABLE:」,錯誤); 0125.nn。確認({信息:'GPS信號弱'}); \t \t \t \t \t \t \t \t休息; \t \t \t \t \t} \t \t \t \t \t \t \t \t \t \t GeoLocation_Not_Supported(); \t \t \t \t}, –

+1

如果PERMISSION_DENIED然後我想打開手機的設置頁面啓用GPS –

回答

0

在Android中,你可以用這樣的方式:

Intent intent = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS); 
startActivityForResult(callGPSSettingIntent, 100); 
+0

請您通過JavaScript或角JS使用代碼幫助我。 –

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

而且在onActivityResult如果用戶已啓用GPS或不

@Override 
    public void onActivityResult(int requestCode, int resultCode, Intent data) { 
     if(requestCode == REQUEST_CODE){ 
      // do your awesome stuff 
     } 
    } 
+0

你能幫我通過使用代碼在JavaScript或角js。 –