本文介绍了地理位置HTML5 enableHighAccuracy真,假或最佳选择?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有关于HTML5地理位置功能的问题。我使用下面的代码来获取位置数据。我使用enableHighAccuracy:false选项来处理Cell Based GPS功能。 Accurancy低,但反应速度太快。但有些人总是使用内置GPS与他们的手机,所以这个代码不适合他们。如果我将合格选项更改为enableHighAccuracy:true,它适用于他们。但是这一次,代码只使用内置的GPS。不是基于CELL的GPS。

i have a problem about HTML5 geolocation feature. I use the code below to get location data. I use "enableHighAccuracy: false" option to work with Cell Based GPS feature. Accurancy is low but response it too fast. But some people always use Built-in GPS with their mobile phone, so this code does not work for them. Bu if i change accurency option as "enableHighAccuracy: true" it works for them. But this time, the code uses only built-in GPS. not CELL based GPS.

问题 - >我该怎么做:首先,如果在这段时间无法获得位置,请尝试从超时(例如5000ms)的内置GPS中获取位置只要查找基于单元格的位置超时(例如10000毫秒),如果此时无法获取位置,则返回错误消息。

The question -> How can i do that : First, try to get position from Built-in GPS with timeout (e.g. 5000ms ) if position cannot be got in this time just look for Cell Based position for timeout (e.g. 10000ms) if position cannot be get in this time, return an error message .

这里是我现在使用的代码。

Here is the code that i use now.

预先感谢。

    function getLocationfromGoogle() {
    navigator.geolocation.getCurrentPosition(
      function(pos) {
        $("#lat_field").val(pos.coords.latitude);
        $("#long_field").val(pos.coords.longitude);
        var geocoder = new google.maps.Geocoder();
        var latLng = new google.maps.LatLng(pos.coords.latitude,pos.coords.longitude);
              geocoder.geocode({ 'latLng': latLng}, function (results, status) {
              if (status == google.maps.GeocoderStatus.OK) {
                //console.log(results[0].formatted_address);
                $("#adresim").val(results[0].formatted_address);
                }
                else {
            alert('Google convertion is not succesfully done.');

            }
            });
      },function error(msg){

                alert('Please enable your GPS position future.');

      },{maximumAge:600000, timeout:5000, enableHighAccuracy: false}

    );
    }


推荐答案

您应该知道这个实现在手机操作系统和手机操作系统之间有所不同 - Android上的功能可能在iOS,黑莓,WindowsPhone等设备上运行或不运行。

You should also be aware that the implementation of this varies from phone OS to phone OS - what works on Android may or may not work on iOS, BlackBerry, WindowsPhone, etc.

,你只需要:

You're almost there, you just need to:


  1. 指定 enableHighAccuracy:true false

  2. 处理错误处理程序中的超时错误大小写。如果来自高精确度查询的错误超时,请使用 enableHighAccuracy:false 再次尝试。

  1. Specify enableHighAccuracy: true (you have it set to false)
  2. Handle the timeout error case in the error handler. If the error from the high accuracy query is timeout, then try it again with enableHighAccuracy: false.

查看此。

您还应该注意,在少数设备上进行测试时,即使 enableHighAccuracy:true ,它也会返回来自WiFi的位置。

You should also note that when testing this on a few devices, it returns location derived from WiFi even when enableHighAccuracy: true.

这篇关于地理位置HTML5 enableHighAccuracy真,假或最佳选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 17:10
查看更多