h5定位geolaction无法调试解决方法
昨天接到一个在h5获取经纬度的需求,看了文档后,代码其实很简单,但在浏览器上调试就比较蛋疼了...
代码:
关于geolaction的介绍,我想这个文档会比我讲得更详细:
https://developer.mozilla.org/zh-CN/docs/Web/API/Geolocation/Using_geolocation
获取经纬度方式有两种:
1.navigator.geolocation.getCurrentPosition(successCallback, errorCallback, options) 【适用于对经度要求不高的,可获得低精度,后两个参数可选】
2.navigator.geolocation.watchPosition(successCallback, errorCallback, options) 【适用于对经度有要求的,可获得高精度,后两个参数可选】
ps:watchPosition()会返回一个 ID,唯一地标记该位置监视器。可将该ID 传给clearWatch(ID)来停止监视用户位置。
本地无服务调试:
1.是否获取地理位置的提示框有时不出来.... 很尴尬;
2.出来了,点击允许就没然后了.... 也很尴尬
3.点击允许后,获得了想要的经纬度 ... 大概要看浏览器心情
公司测试环境看效果:
是否同意获取地理位置的弹框始终不出来..... 我一度以为是代码问题or环境问题【公司项目比较老】
后发现这个提示:

搜了下CanIus里各浏览器支持情况:

查看其CanIUse里的notice,会发现,geolocation越往后基本就只支持https请求的,点击测试环境里浏览器提示里的链接,里面提供了非安全环境(即http环境)测试方法:
https://sites.google.com/a/chromium.org/dev/Home/chromium-security/deprecating-powerful-features-on-insecure-origins
粘贴部分原文如下:
Testing Powerful Features
- Secure the server with a publicly-trusted certificate. If the server is reachable from the Internet, several public CAs offer free, automatically-renewed server certificates.
- http://localhost is treated as a secure origin, so if you're able to run your server from localhost, you should be able to test the feature on that server.
- You can run chrome with the --unsafely-treat-insecure-origin-as-secure="http://example.com" flag (replacing "example.com" with the origin you actually want to test), which will treat that origin as secure for this session. Note that on Android and ChromeOS this requires having a device with root access/dev mode. (This flag is broken in Chrome 63 but fixed in Chrome 64 and later. Prior to Chrome 62, you must also include the --user-data-dir=/test/only/profile/dir to create a fresh testing profile for the flag to work.)
- Create a self-signed certificate for temporary testing. Direct use of such a certificate requires clicking through an invalid certificate interstitial, which is otherwise not recommended. Note that because of this interstitial click-through (which also prevents HTTPS-response caching), we recommend options (1) and (2) instead, but they are difficult to do on mobile. See this post on setting up a self-signed certificate for a server for more information on how to do this.
An alternative approach is to generate a self-signed root certificate which you place into the trust store of the developer PC/devices, and then issue one or more certificates for the test servers. Trusting the root certificate means that Chrome will treat the site as secure and load it without interstitials or impacting caching. One easy way of setting up and using a custom root certificate is to use the open source mkcert tool.

h5定位geolaction无法调试解决方法的更多相关文章
- Segger RTT : Real Time Terminal SRAM 调试解决方法
http://segger.com/jlink-real-time-terminal.html Real Time Terminal SEGGER's Real Time Terminal (RTT) ...
- ADF控件ID变化引发JS无法定位控件的解决方法
原文地址:ADF控件ID变化引发JS无法定位控件的解决方法作者:Nicholas JSFF定义的控件ID到了客户端时往往会改变.例如在JSFF中的一个的ID为"ot1",但是当这个 ...
- Android 10不能使用uiautomatorviewer定位元素的终极解决方法
Android app 元素定位除了使用Appium Inspector 外,还可以使用Android SDK 里tools中的uiautomatorviewer 工具.但今天打算使用 uiautom ...
- 关于百度地图js api的getCurrentPosition定位不准确的解决方法
很久之前帮大叔解决了一个gps坐标转换为百度地图坐标的问题.今天大叔又给我讲百度地图定位不准.我查了一下api,用了官方给出的这样一组函数. //创建查询对象 var geolocation = ne ...
- Android 进入页面默认定位到ListView的解决方法
由于ListView会默认去获取焦点,如果说ListView在页面的下方的话,那么点击条目进入新页面并退出,那么这时候就会定位到ListView这里,而不是展示头部. 解决这个问题,只需要在Lis ...
- autodesk fbx sdk sample里面的工程无法调试解决方法
1.项目属性->常规中的目标文件名改为1 2.链接器->调试中的生成程序数据库文件改成:$(OutDir)1.pdb 3.连接器->常规中的输出文件改成:$(OutDir)1.exe ...
- 关于selenium无法定位动态元素的解决方法
今天在写一个关于登录的自动化脚本时,在对元素定位时总会报下面的错:
- Thinkphp5.1允许uni-app的H5跨域请求接口解决方法
情景: uni-app使用vue框架开发混合APP,虽然APP或者小程序没有跨域,但希望就是写完这个既有H5,又有APP,小程序等,所以能通过后端解决跨域最好.但是不知道是vue的原因还是什么,在PH ...
- h5页面滑动卡顿解决方法
解决方式: 给滚动的元素加样式:-webkit-overflow-scrolling: touch; -webkit-overflow-scrolling(允许独立的滚动区域和触摸回弹) 如果值为au ...
随机推荐
- Go学习笔记01-环境搭建
最近想学学Go语言,就在笔记本上配置了Go的环境. 本人的运行环境为:Windows 10 1709. 1.下载安装包 到官网下载安装包,官网网址为:Go安装包下载地址 现在Go的最新版本为1.9.2 ...
- 1.4 Genymotion模拟器安装
如果你符合下述三种情况的话,你可以考虑安装一个Genymotion Android模拟器: 没有真机调试,只能用模拟器 嫌SDK内置的AVD启动速度,运行速度慢 电脑配置还可以,最好4G内存以上 如果 ...
- ORB-SLAM2(2) ROS下配置和编译
1配置USB相机 1.1网友参考: http://www.liuxiao.org/2016/07/ubuntu-orb-slam2-%E5%9C%A8-ros-%E4%B8%8A%E7%BC%96%E ...
- python3 用户登录 day01
'''用户登录作业需求:1. 三次重试机会2. 每次输错误时显示剩余错误次数'''num = 1while num <= 3: username = input("请输入用户名:&qu ...
- 学习CSS布局 - position
position 为了制作更多复杂的布局,我们需要讨论下 position 属性. 它有一大堆的值,名字还都特抽象,别提有多难记了. 让我们先一个个的过一遍,不过你最好还是把这页放到书签里. 先看下运 ...
- linux笔记-多服务器同时执行相同命令
1.服务器的ip地址写到文件中,命名为nodelist.txt 192.168.1.160 192.168.1.166 2.编写运行脚本 for i in `cat nodelist.txt`do s ...
- Wi-Fi无线控制器开发例程(基础篇)
动手来做自己的WIFI远程控制插座吧! 如果感觉视频不容易入门可以看这里 https://www.cnblogs.com/yangfengwu/p/10100152.html WIFI远程控制器系统方 ...
- ASP.NET Core读取AppSettings (转载)
今天在把之前一个ASP.NET MVC5的Demo项目重写成ASP.NET Core,发现原先我们一直用的ConfigurationManager.AppSettings[]读取Web.config中 ...
- CF1110E Magic Stones 差分
传送门 将原数组差分一下,设\(d_i = c_{i+1} - c_i\) 考虑在\(i\)位置的一次操作会如何影响差分数组 \(d_{i+1}' = c_{i+1} - (c_{i+1} + c_{ ...
- Luogu4546 THUWC2017 在美妙的数学王国中畅游 LCT、泰勒展开
传送门 题意:反正就是一堆操作 LCT总是和玄学东西放在一起我们不妨令$x_0=0.5$(其实取什么都是一样的,但是最好取在$[0,1]$的范围内),将其代入给出的式子,我们得到的$f(x)$的式子就 ...