我对 HTML5 地理定位功能有疑问.我使用下面的代码来获取位置数据.我使用enableHighAccuracy: false"选项来处理基于蜂窝的 GPS 功能.准确率低,但反应太快.但是有些人总是在手机上使用内置 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.
问题 -> 我该怎么做:首先,如果此时无法获得位置,请尝试从内置 GPS 超时(例如 5000 毫秒)获取位置,只需查找基于单元的位置超时(例如 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:
enableHighAccuracy: true(您已将其设置为 false)enableHighAccuracy: false 重试.enableHighAccuracy: true (you have it set to false)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 True 、 False 还是最佳选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
Angular 2:在本地 .json 文件中找不到文件Angular 2: file not found on local .json file(Angular 2:在本地 .json 文件中找不到文件)
在 Ionic 2 中,如何创建使用 Ionic 组件的自定义指In Ionic 2, how do I create a custom directive that uses Ionic components?(在 Ionic 2 中,如何创建使用 Ionic 组件的自定义指令?)
如何在 ionic2 中的 pop() 之后重新加载离子页面How to reload the ion-page after pop() in ionic2(如何在 ionic2 中的 pop() 之后重新加载离子页面)
Javascript 将 URL 转换为 BASE64 图像Javascript Convert an URL to a BASE64 Image(Javascript 将 URL 转换为 BASE64 图像)
使用模式 Angular 2 进行输入验证Input validation with pattern Angular 2(使用模式 Angular 2 进行输入验证)
如何在角度2中动态更改css类名How to change the css class name dynamically in angular 2(如何在角度2中动态更改css类名)