<legend id='ONG8b'><style id='ONG8b'><dir id='ONG8b'><q id='ONG8b'></q></dir></style></legend>

<small id='ONG8b'></small><noframes id='ONG8b'>

<tfoot id='ONG8b'></tfoot>
    • <bdo id='ONG8b'></bdo><ul id='ONG8b'></ul>

        <i id='ONG8b'><tr id='ONG8b'><dt id='ONG8b'><q id='ONG8b'><span id='ONG8b'><b id='ONG8b'><form id='ONG8b'><ins id='ONG8b'></ins><ul id='ONG8b'></ul><sub id='ONG8b'></sub></form><legend id='ONG8b'></legend><bdo id='ONG8b'><pre id='ONG8b'><center id='ONG8b'></center></pre></bdo></b><th id='ONG8b'></th></span></q></dt></tr></i><div id='ONG8b'><tfoot id='ONG8b'></tfoot><dl id='ONG8b'><fieldset id='ONG8b'></fieldset></dl></div>

        如何防止 Phonegap 应用程序中的地理定位双重提示

        时间:2023-09-01

            • <bdo id='ySrx6'></bdo><ul id='ySrx6'></ul>
                <tbody id='ySrx6'></tbody>

              <small id='ySrx6'></small><noframes id='ySrx6'>

              • <legend id='ySrx6'><style id='ySrx6'><dir id='ySrx6'><q id='ySrx6'></q></dir></style></legend>

                • <tfoot id='ySrx6'></tfoot>
                  <i id='ySrx6'><tr id='ySrx6'><dt id='ySrx6'><q id='ySrx6'><span id='ySrx6'><b id='ySrx6'><form id='ySrx6'><ins id='ySrx6'></ins><ul id='ySrx6'></ul><sub id='ySrx6'></sub></form><legend id='ySrx6'></legend><bdo id='ySrx6'><pre id='ySrx6'><center id='ySrx6'></center></pre></bdo></b><th id='ySrx6'></th></span></q></dt></tr></i><div id='ySrx6'><tfoot id='ySrx6'></tfoot><dl id='ySrx6'><fieldset id='ySrx6'></fieldset></dl></div>

                  本文介绍了如何防止 Phonegap 应用程序中的地理定位双重提示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我为 iPhone 创建了一个 PhoneGap 应用,它通过 webview 中的 JavaScript 使用地理定位.

                  I created a PhoneGap app for iPhone that uses geolocation via JavaScript inside webview.

                  当我第一次运行该应用程序时,它会提示我允许此应用程序的地理定位.

                  When I run the app the first time, it'll prompt me to allow geolocation for this app.

                  当我点击ok"时,它会再次提示我同样的问题,但这次它指出index.html"需要使用地理位置的权限.

                  When I hit "ok", it'll prompt me again with the same question but this time it states that "index.html" wants permission to use geolocation.

                  这是有道理的,因为 iOS 可能第一次需要允许应用程序本身的地理定位权限,而浏览器第二次需要权限.

                  That makes sense because iOS probably wants permission to allow geolocation for the app itself for the first time and the 2nd time the browser wants permission.

                  但是,因为不会带来出色的用户体验:

                  However, since doesn't lead to a great user experience:

                  如何防止这种双重提示?(如果可以防止第二个提示就足够了)

                  How can I prevent this double prompt? (I'd be enough if the 2nd prompt could be prevented)

                  推荐答案

                  我找到了问题的原因.

                  navigator.geolocation.getCurrentPosition(onsuccess, onerror) 的调用发生在 Phonegap 完全加载之前.

                  The call to navigator.geolocation.getCurrentPosition(onsuccess, onerror) happens before Phonegap was fully loaded.

                  这意味着 webview 的地理定位调用(而不是通过 PhoneGap 的本地调用)被触发,这将再次请求许可(这确实有意义).将其与智能手机上的普通 Safari 浏览器进行比较.它会要求每个新网站的地理位置许可.应用启动时通过PhoneGap加载index.html也是一样.

                  This means that the geolocation call of webview (and not a native call via PhoneGap) is being triggered which will again ask for permission (which does make sense). Compare it to the normal Safari browser on your Smartphone. It'll ask for geolocation permission for every new website. It's the same when loading index.html via PhoneGap on application startup.

                  但是,解决方案是等待在 PhoneGap 完全加载时触发的 deviceready 事件:

                  However, the solution is to wait for the deviceready event which gets fired when PhoneGap has fully loaded:

                  document.addEventListener("deviceready", function(){
                       navigator.geolocation.getCurrentPosition(onsuccess, onerror, params);
                  }, false);
                  

                  这将使 PhoneGap API 可用,它会覆盖浏览器的默认 HTML5 地理定位调用,并通过本机调用(您已在第一个提示中接受)获取设备的地理位置.

                  This will make the PhoneGap API available which overwrites the default HTML5 gelocation call of the browser and get the device's geo location via a native call (which you already accepted in the first prompt).

                  这会起作用,因为 PhoneGap 的 API 调用与 HTML5 的标准 W3C 调用相同:http://docs.phonegap.com/en/2.2.0/cordova_geolocation_geolocation.md.html#Geolocation

                  This will work because PhoneGap's API calls are identical to the standard W3C call for HTML5: http://docs.phonegap.com/en/2.2.0/cordova_geolocation_geolocation.md.html#Geolocation

                  这篇关于如何防止 Phonegap 应用程序中的地理定位双重提示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:iPhone - 从照片中获取位置信息 下一篇:在 Android 中步行/驾驶时更新位置标记并在 Googl

                  相关文章

                  最新文章

                • <small id='cJiZd'></small><noframes id='cJiZd'>

                  <i id='cJiZd'><tr id='cJiZd'><dt id='cJiZd'><q id='cJiZd'><span id='cJiZd'><b id='cJiZd'><form id='cJiZd'><ins id='cJiZd'></ins><ul id='cJiZd'></ul><sub id='cJiZd'></sub></form><legend id='cJiZd'></legend><bdo id='cJiZd'><pre id='cJiZd'><center id='cJiZd'></center></pre></bdo></b><th id='cJiZd'></th></span></q></dt></tr></i><div id='cJiZd'><tfoot id='cJiZd'></tfoot><dl id='cJiZd'><fieldset id='cJiZd'></fieldset></dl></div>

                      • <bdo id='cJiZd'></bdo><ul id='cJiZd'></ul>
                      <tfoot id='cJiZd'></tfoot><legend id='cJiZd'><style id='cJiZd'><dir id='cJiZd'><q id='cJiZd'></q></dir></style></legend>