【问题标题】:Geolocation not working iOS地理位置无法正常工作iOS
【发布时间】:2015-05-13 07:27:35
【问题描述】:

我正在开发一个混合移动应用程序,并试图让 HTML5 Geolocation 在 iPhone IOS8 上运行,但没有运气。有谁知道任何已知的问题?我尝试了很多示例,但没有一个甚至提示用户允许地理定位。它在浏览器中运行良好,但是一旦上传到 PhoneGap Build 并安装在我的手机上,它就什么也做不了。

我尝试过的一些示例代码是:

 <!DOCTYPE html>
 <html>
 <body>

 <p>Click the button to get your coordinates.</p>

 <button onclick="getLocation()">Try It</button>

 <p id="demo"></p>

 <script>
 var x = document.getElementById("demo");

 function getLocation() {
     if (navigator.geolocation) {
         navigator.geolocation.getCurrentPosition(showPosition);
     } else { 
         x.innerHTML = "Geolocation is not supported by this browser.";
     }
 }

 function showPosition(position) {
     x.innerHTML = "Latitude: " + position.coords.latitude + 
     "<br>Longitude: " + position.coords.longitude; 
 }
 </script>

 </body>
 </html>

我会使用 PhoneGap 插件,但无法正常工作。

谢谢。

【问题讨论】:

  • 您是否包含地理定位插件?
  • @jcesarmobile 是的,我相信我做对了。 我把它放在 config.xml 的顶部

标签: javascript html cordova permissions geolocation


【解决方案1】:

尝试在设备准备就绪时使用该命令。

之后,如果地理定位不起作用:尝试使用陀螺仪插件进行简单测试。

【讨论】:

    【解决方案2】:

    为 iOS 安装插件并在配置文件中调用它们

    从这里下载插件: https://github.com/apache/cordova-plugin-geolocation.git

     <feature name="Geolocation">
        <param name="ios-package" value="CDVLocation" />
    </feature>
    

    希望对你有帮助

    【讨论】: