2016-09-15 140 views
0

我遇到了一個問題,我剛剛注意到並且從未見過我以前發佈的代碼。在js我打電話在Android設備上使用Chrome時出現的Modernizr錯誤

navigator.geolocation.getCurrentPosition()... 

我也編寫了回調的成功和錯誤部分。我遇到的問題是,在使用Chrome的Android設備上,我總是收到錯誤「[object PositionError]」

如果我在同一臺設備上使用Firefox,那很好。我測試過的所有iOS設備也可以使用。

是否有其他人遇到這個問題,如果是的話,你找到了解決辦法。

這是我的代碼完全塊:

if (Modernizr.geolocation) { 
    navigator.geolocation.getCurrentPosition(
     function (position) { 
      var lat = position.coords.latitude; 
      var lng = position.coords.longitude; 
      callback(lat, lng); 
     } 
     , function (err) { 
      // 1 = PERMISSION_DENIED 
      // 2 = POSITION UNAVAILABLE 
      // 3 = TIMEOUT 
      //if (err.code == err.PERMISSION_DENIED) { 
      alert(err); 
      alert('Current location could not be obtained from the device.\r\nCheck your GPS settings.'); 
      //} 
     } 
     , { timeout: 10000 }//10 secs. 
    ); 
} else { 
    alert('This device does not support GPS locations.'); 
} 
+0

您是在http或https頁面上運行此代碼嗎? – Patrick

+0

這是http不是https – JimboJones

回答

0

As of Chrome 50,您將不再能夠從非HTTPS網頁訪問地理位置API。

感謝像Lets Encrypt這樣的項目,您現在可以免費獲得SSL證書。

+0

謝謝。 我會跟我的網絡管理員進行設置。我查看了該網站,但沒有看到爲Windows IIS設置它的方法。 再次感謝,至少我知道這可以現在修復。 – JimboJones

+0

查看https://github.com/ebekker/ACMESharp – Patrick

相關問題