移动设备中的HTML 5地理位置POSITION UNAVAILABLE错误 [英] HTML 5 geolocation POSITION UNAVAILABLE error in mobile

查看:2404
本文介绍了移动设备中的HTML 5地理位置POSITION UNAVAILABLE错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试在移动网络应用程序中获取用户当前位置
我的应用程序可以在除三星galaksy s2电话设备之外的所有android电话设备上工作。
它给出错误POSITION UNAVAILABLE错误

这是演示链接。您可以查看源
这是代码

  navigator.geolocation.getCurrentPosition(handle_geolocation_query1,handle_errors); 
函数handle_errors(错误){
switch(error.code){
case error.PERMISSION_DENIED:alert(用户不共享地理位置数据);
休息;
case error.POSITION_UNAVAILABLE:alert(无法检测到当前位置);
休息;
case error.TIMEOUT:alert(检索位置超时);
休息;
默认值:alert(未知错误);
休息;


函数handle_geolocation_query1(position){



$('#map_canvas').gmap('addMarker', {
'id':'m_1',
'position':new google.maps.LatLng(position.coords.latitude,position.coords.longitude),
'bounds':true ,
'图标':'http://google-maps-utility-library-v3.googlecode.com/svn/trunk/geolocationmarker/images/gpsloc.png'
})。click(function (){
$('#map_canvas')。gmap('openInfoWindow',{'content':'< font color =#2a2a2asize =4>位置< / font>< ; br />< font color =#4a4a4a>您当前的位置< / 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);



}

编辑:
i使用phonegap生成android apk文件
当我工作这个apk文件应用程序时,它给出了错误POSITION UNAVAILABLE错误,但是当我从网络调用这个页面时,它的工作原理并没有给出错误...这是web 链接,你可以从 here 解决方案

您的代码在浏览器中工作正常,但不在手机中。



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

em>。

 < script type =text / javascriptsrc =http://maps.google.com/地图/ API / JS传感器=假>?< /脚本> 

您在检查 documentation


$ b


指定传感器参数应用程序是否使用传感器(例如GPS定位器)来确定$ b $(

b用户的位置。这对移动设备来说尤其重要。
当包含Maps API JavaScript代码时,应用程序必须将所需的传感器参数传递到标记
,指示是否
您的应用程序正在使用传感器设备。

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


希望您能理解。

i am trying to get user current position in mobile web application my app work in all android telephone device except samsung galaksy s2 telephone device .. it give errror POSITION UNAVAILABLE error
this is demo link.you can view source this is code

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);



            }

edited: i used phonegap to produce android apk file when i work this apk file application it give error POSITION UNAVAILABLE error but when i call this page from web it works it does not give error ... this is web link and you can download apk from here

解决方案

Your code is working fine in browser but not in mobile.

On checking your source code it seems you're specifying the sensor parameter as false.

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

You missed this while checking the documentation.

Specifying the Sensor Parameter

Use of the Google Maps API requires that you indicate whether your application is using a sensor (such as a GPS locator) to determine the user's location. This is especially important for mobile devices. Applications must pass a required sensor parameter to the tag when including the Maps API javascript code, indicating whether or not your application is using a sensor device.

Applications that determine the user's location via a sensor must pass sensor=true when loading the Maps API JavaScript.

Hope you understand.

这篇关于移动设备中的HTML 5地理位置POSITION UNAVAILABLE错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆