移动设备中的HTML 5地理定位POSITION UNAVAILABLE错误

时间:2013-08-07 15:43:45

标签: html5 google-maps google-maps-api-3 geolocation w3c-geolocation

我想让用户在移动网络应用程序中获得当前位置 我的应用程序在所有Android电话设备工作,除了三星galaksy s2电话设备.. 它给errror POSITION UNAVAILABLE错误
这是demo link.you可以查看来源 这是代码

navigator.geolocation.getCurrentPosition(handle_geolocation_query1, handle_errors) ;
       function handle_errors(error) {
            switch (error.code) {
                    case error.PERMISSION_DENIED: alert("user did not share geolocation data");
                        break;
                    case error.POSITION_UNAVAILABLE: alert("could not detect current position");
                        break;
                    case error.TIMEOUT: alert("retrieving position timed out");
                        break;
                    default: alert("unknown error");
                        break;
                }
            } 
       function handle_geolocation_query1(position) {



               $('#map_canvas').gmap('addMarker', {
                     'id':'m_1',
                    'position': new google.maps.LatLng(position.coords.latitude,position.coords.longitude),
                    'bounds': true,
                    'icon': 'http://google-maps-utility-library-v3.googlecode.com/svn/trunk/geolocationmarker/images/gpsloc.png'
                }).click(function () {
           $('#map_canvas').gmap('openInfoWindow',{ 'content': '<font color="#2a2a2a" size="4">Location </font><br/><font color="#4a4a4a">Your current location</font>' }, this);
                });
                 var map = $('#map_canvas').gmap('get', 'map');
                map.setZoom(14);
                map.setCenter(new google.maps.LatLng(41.01802007732287, 28.971880674362183));
                map.setMapTypeId(google.maps.MapTypeId.ROADMAP);



            }

编辑: 我用phonegap来生成安卓apk文件 当我工作这个apk文件应用程序时,它给错误POSITION UNAVAILABLE错误,但当我从网络上调用此页面时,它的工作原理并没有给出错误...这是web link,你可以从here下载apk

3 个答案:

答案 0 :(得分:2)

您的代码在浏览器中运行良好,但在移动设备中运行良好。

在检查源代码时,您似乎将传感器参数指定为false

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>

您在检查documentation时错过了此项。

  

指定传感器参数

     

使用Google Maps API需要您指明是否   应用程序正在使用传感器(如GPS定位器)来确定   用户的位置。这对于移动设备来说非常重要。   应用程序必须将所需的传感器参数传递给标记   当包含Maps API javascript代码时,指示是否   您的应用程序正在使用传感器设备。

     

通过传感器确定用户位置的应用程序必须通过   加载Maps API JavaScript时,sensor = true。

希望你明白。

答案 1 :(得分:0)

在我的设备上,我将“位置”模式的设置设置为“仅设备”。 在这种情况下,我无法很好地联系到位置,因此无法获得“位置不可用”。 我更改设置>位置>模式,并将其更改为高精度。 我花了很多天的时间才知道此问题是在设备本身中引起的,但仍无法解决。我尽了最大的能力来修复代码,甚至可以追溯到插件的代码。 请尊重我的帖子。有些人也可能有这个问题。谢谢。

答案 2 :(得分:0)

Messenger Webview出现相同的错误,电话设置中拒绝了Messenger的位置,因此在允许Messenger应用程序的位置共享后,该错误得以解决。

相关问题