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

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

        <bdo id='Y7iXT'></bdo><ul id='Y7iXT'></ul>
    1. <tfoot id='Y7iXT'></tfoot>
    2. android上的javascript地理定位不起作用

      时间:2023-09-02

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

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

        <tbody id='hlMtX'></tbody>

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

                本文介绍了android上的javascript地理定位不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我正在开发一个依赖于提取移动用户的地理位置数据的网站.我通过以下方式以典型方式进行操作:

                I am developing a website that relies on pulling the geolocation data of a mobile user. I am doing it the typical way via:

                function initialize() {
                   if(window.google && google.gears) {
                        var geo = google.gears.factory.create('beta.geolocation');
                        geo.getCurrentPosition(useLocation, errorOnLocate);
                   }
                   else if(navigator.geolocation) {
                       navigator.geolocation.getCurrentPosition(useLocation, errorOnLocate);
                   }
                   else {
                       alert("no geo found");
                   }
                }
                
                function errorOnLocate(message)
                {
                    alert(message);
                    zoomTo(-34.397, 150.644);
                }
                

                即使我切换地理定位方法顺序,这总是会在 errorOnLocate 函数中出现 [object PositionError] 失败.

                This always fails with [object PositionError] in to the errorOnLocate function, even if I switch the geolocation method order.

                这是使用任何内置浏览器的 HTC Hero 和 android 2.1.我的 gps 已打开,我已指示浏览器允许网站查看我的位置.手机自带的谷歌地图原生应用程序的位置"功能可以很好地获取我的位置

                This is on an HTC Hero with android 2.1 using whatever browser is built in. My gps is on and I have instructed the browser to allow websites to view my location. The "location" feature on the google map native application that comes on the phone picks up my location just fine

                如果我在个人计算机上使用 FireFox 3.5 访问我的网站,它会正确找到我的位置.(我相信它使用了 ip 和 ap 数据点的组合).无论哪种方式,它都使用相同的 javascript.

                Further more if I visit my site using FireFox 3.5 on my personal computer it will find my location correctly.(I believe it uses a combination of ip and ap data points). Either way, it uses the same javascript.

                这是浏览器中的 html/js,而不是本机应用程序.此外,确切的错误消息是最后一个位置提供程序被禁用"

                This is html/js in a browser, not a native app. Also the exact error message is 'The last location provider was disabled'

                推荐答案

                这是从 WebView 还是从 Android 浏览器应用程序访问的?如果来自 WebView,您可能需要通过 Java 调用启用地理定位.请参阅 WebView 参考.

                Is this being accessed from a WebView or from the Android Browser app? If from a WebView, you may need to enable geolocation via a Java call. See the WebView reference for that.

                否则,我不确定您的 JS 到底出了什么问题,但我知道这里的 HTML+JS 适用于 Android 浏览器:

                Otherwise, I'm not sure precisely what's wrong with your JS, but here's HTML+JS that I know works with the Android browser:

                <!DOCTYPE html> 
                <html> 
                <head> 
                  <script type="text/javascript"> 
                function watchLocation(successCallback, errorCallback) {
                  successCallback = successCallback || function(){};
                  errorCallback = errorCallback || function(){};
                
                  // Try HTML5-spec geolocation.
                  var geolocation = navigator.geolocation;
                
                  if (geolocation) {
                    // We have a real geolocation service.
                    try {
                      function handleSuccess(position) {
                        successCallback(position.coords);
                      }
                
                      geolocation.watchPosition(handleSuccess, errorCallback, {
                        enableHighAccuracy: true,
                        maximumAge: 5000 // 5 sec.
                      });
                    } catch (err) {
                      errorCallback();
                    }
                  } else {
                    errorCallback();
                  }
                }
                
                function init() {
                  watchLocation(function(coords) {
                    document.getElementById('test').innerHTML = 'coords: ' + coords.latitude + ',' + coords.longitude;
                  }, function() {
                    document.getElementById('test').innerHTML = 'error';
                  });
                }
                  </script> 
                </head> 
                
                <body onload="init()"> 
                  <div id="test">Loading...</div> 
                </body> 
                </html>
                

                这篇关于android上的javascript地理定位不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:onLocationChanged 不会自动调用 下一篇:网络位置提供商不提供位置 android

                相关文章

                最新文章

              • <small id='8aJCK'></small><noframes id='8aJCK'>

              • <legend id='8aJCK'><style id='8aJCK'><dir id='8aJCK'><q id='8aJCK'></q></dir></style></legend>

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