首页 » HTML/CSS » Chrome android关于getCurrentPosition的参数positionOptions错误表现

Chrome android关于getCurrentPosition的参数positionOptions错误表现

9498 2

看题目很拗口,tiandi也不知道是否表述的正确。说的具体点就是,html5有个叫Geolocation的东西,这个东西封装在 navigator.geolocation 属性里,具体的作用是能显示浏览器的地址位置。它有一个方法叫做getCurrentPosition,而这个方法有3个参数,即getCurrentPosition(successCallback,errorCallback,positionOptions)。其中第三个参数就是本文标题所说的,Chrome andriod版本好像完全忽略了此参数,当然桌面版的Chrome好像没有这个问题。

positionOptions参数是一个json的形式,有三个值:

enableHighAcuracy — 布尔值: 表示是否启用高精确度模式,如果启用这种模式,浏览器在获取位置信息时可能需要耗费更多的时间。

timeout — 整数: 表示浏览需要在指定的时间内获取位置信息,否则触发errorCallback。

maximumAge — 整数/常量: 表示浏览器重新获取位置信息的时间间隔。

这里涉及到的就是enableHighAcuracy,这个参数默认是false,只需要WIFI或者GPRS即可进行模糊定位,当变为true时,表示需要gps进行精确定位。

来看一下下面的代码,代码来自天地团,实际运用当中,tiandi发现Chrome android版下关闭gps功能后,如果用到getCurrentPositionI(successCallback,errorCallback,null)的话,即第3个参数选为默认值,Chrome android会报错PERMISSION_DENIED,而用UCWEB则不会。

var geo = navigator.geolocation;
		geo.getCurrentPosition(function (pos) {  
		var coord = pos.coords;                
		accuracy = coord.accuracy;              
		latitude = coord.latitude;     
		longitude = coord.longitude; 
		//alert(latitude+"|"+longitude);
		searchajax(city,latitude,longitude);
     },
  function (error) {
  switch(error.code) 
    {
    case error.PERMISSION_DENIED:
      alert("User denied the request for Geolocation.");
      break;
    case error.POSITION_UNAVAILABLE:
      alert("Location information is unavailable.");
      break;
    case error.TIMEOUT:
      alert("The request to get user location timed out.");
      break;
    case error.UNKNOWN_ERROR:
      alert("An unknown error occurred.");
      break;
    }
  });

Geolocation

具体可以分别用UCWEB和Chrome android点击导航页上的天地团的附近功能来查看。

姑且这里就当它是一个Chrome android版上的bug吧。

文章评分2次,平均分3.5

本文原始地址:https://www.tiandiyoyo.com/2014/05/chrome-android-has-bug-on-geolocation/
本站所有文章,除了特别注明外,均为本站原创,转载请注明出处来自www.tiandiyoyo.com

您可能还会对以下文章感兴趣:

    没有相关的文章

评论前先开启评论开关:


2 Comments

  1. 屠龙 :

    分享了这篇文章,感觉很复杂。

载入分页评论...