完美解决window.navigator.geolocation.getCurrentPosition,在IOS10系统中无法定位问题
目前由于许多用户都将电话升级到了iOS系统,苹果的iOS 10已经正式对外推送,相信很多用户已经更新到了最新的系统。然而,如果web站没有及时支持https协议的话,当很多用户在iOS 10下访问很多网站时,会发现都无法进行正常精确定位,导致部分网站的周边推荐服务无法正常使用。为何在iOS 10下无法获取当前位置信息?这是因为在iOS 10中,苹果对webkit定位权限进行了修改,所有定位请求的页面必须是https协议的。如果是非https网页,在http协议下通过HTML5原生定位接口会返回错误,也就是无法正常定位到用户的具体位置,而已经支持https的网站则不会受影响。
目前提供的解决方案:
1、将网站的http设置为Https。
2、通过第三方解决,这也是我目前使用的方法。
首先看下代码差异:
1、在页面引入js
- <script src="/Content/Scripts/jquery.flexslider.js"></script>
- <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=6yAoynmTPNlTBa8z1X4LfwGE"></script>
- <script type="text/javascript" src="http://developer.baidu.com/map/jsdemo/demo/convertor.js"></script>
window.navigator.geolocation.getCurrentPosition:通过手机的webKit定位(目前ios系统对非https网站不提供支持)
- navigator.geolocation.getCurrentPosition(translatePoint); //定位
- function translatePoint(position) {
- var currentLat = position.coords.latitude;
- var currentLon = position.coords.longitude;
- SetCookie("curLat", currentLat, 1);//设置cookie
- SetCookie("curLng", currentLon, 1);//设置cookie
- var gpsPoint = new BMap.Point(currentLon, currentLat);
- var pt = new BMap.Point(currentLon, currentLat);
- var geoc = new BMap.Geocoder();
- geoc.getLocation(pt, function (rs) {
- var addComp = rs.addressComponents;
- SetCookie("curLat", currentLat, 1); //设置cookie
- SetCookie("curLng", currentLon, 1); //设置cookie
- //alert(JSON.stringify(addComp));
- var city = addComp.city;
- //获得具体街道信息
- var texts = addComp.district + "-" + addComp.street + "-" + addComp.streetNumber;
- $("#nowRoad").text(texts);
- });
2、网站不支持https访问
1、页面引入js
- <script src="/Content/Scripts/jquery.flexslider.js"></script>
- <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=6yAoynmTPNlTBa8z1X4LfwGE"></script>
- <script type="text/javascript" src="http://developer.baidu.com/map/jsdemo/demo/convertor.js"></script>
2、获得定位方法
- var geolocation = new BMap.Geolocation();
- geolocation.getCurrentPosition(function (r) {
- if (this.getStatus() == BMAP_STATUS_SUCCESS) {
- var mk = new BMap.Marker(r.point);
- currentLat = r.point.lat;
- currentLon = r.point.lng;
- SetCookie("curLat", currentLat, 1); //设置cookie
- SetCookie("curLng", currentLon, 1); //设置cookie
- var pt = new BMap.Point(currentLon, currentLat);
- var geoc = new BMap.Geocoder();
- geoc.getLocation(pt, function (rs) {
- var addComp = rs.addressComponents;
- SetCookie("curLat", currentLat, 1); //设置cookie
- SetCookie("curLng", currentLon, 1); //设置cookie
- var city = addComp.city;
- var addComp = rs.addressComponents;
- var texts = addComp.district + "-" + addComp.street + "-" + addComp.streetNumber;
- //获取地理位置成功,跳转
- }
完美解决window.navigator.geolocation.getCurrentPosition,在IOS10系统中无法定位问题的更多相关文章
- 解决window.navigator.geolocation.getCurrentPosition在IOS10系统中无法进行地理定位问题
昨天接到用户通知说在点击"看场地"时无法获取地理位置信息. 在接到通知时,首先想到的是排查机型问题.由于客户多为IOS用户,所以最先看的是在安卓是有没有此问题的发生,调查结果为安卓 ...
- navigator.geolocation在IOS10系统中无法定位问题
在使用地图需要定位的朋友都可能遇到这个问题,参考的文章说的是用百度地图,我用的是腾讯地图,但是其中的原理差不多.所以谢谢这些提供资源的大神们. if (navigator.geolocation) { ...
- 在IOS10系统中无法定位问题
果是非https网页,在http协议下通过html5原生定位接口会返回错误,也就是无法正常定位到用户的具体位置,而已经支持https的网站则不会受影响. 目前提供的解决方案: 1.将网站的http设置 ...
- IOS10 window.navigator.geolocation.getCurrentPosition 无法定位问题
在iOS 10中,苹果对webkit定位权限进行了修改,所有定位请求的页面必须是https协议的. 如果是非https网页,在http协议下通过HTML5原生定位接口会返回错误,也就是无法正常定位到用 ...
- 用navigator.geolocation.getCurrentPosition在IOS10以上的系统无法定位
昨天老板告诉我代码有Bug(定位失败),于是各种测试最终发现IOS10以上版本手机不能成功(穷,买不起iphone,测试不完全),先贴失败代码: var city =""; nav ...
- HTML5浏览器定位navigator.geolocation.getCurrentPosition
<!DOCTYPE html> <html> <body> <p id="demo">点击这个按钮,获得您的坐标:</p> ...
- 【H5】 经纬度位置获取navigator.geolocation.getCurrentPosition
navigator.geolocation.getCurrentPosition(function(){})经度 : coords.longitude 纬度 : coords.latitude 准确度 ...
- navigator.geolocation.getCurrentPosition
navigator.geolocation.getCurrentPosition Geolocation API Specification 2nd Edition W3C Recommendatio ...
- js定位navigator.geolocation
一.简介 html5为window.navigator提供了geolocation属性,用于获取基于浏览器的当前用户地理位置. window.navigator.geolocation提供了3个方法分 ...
随机推荐
- 用EmEditor实现PDF转Word后的对齐排版
Redraw = false//禁止重绘(类似于VBA中的: Application.screenupdating=FALSE),以提高运行效率 //去除所有空行和只由空白字符构成的行 documen ...
- CSS Icon 项目地址 小图标-用css写成的
http://cssicon.space/#/icon/focus 这是所有用css写成的 小图标 右侧有 html和css代码
- neo4j关闭和开启密码访问权限
本例:neo4j-enterprise-2.3.1版本 neo4j默认安装是开启访问密码验证 可以发现,在conf/下的neo4j-server.properties配置文件 # Require (o ...
- Java常见Exception整理
前言: 技术开发入坑近1年,摸打滚爬,各种升级打怪.因目前从事Java相关,故整理了一下并把常见的异常(Exception)贴出来,一来为了后续提醒自己,二来供即将入坑的朋友打一下预防针!A级(代码逻 ...
- Android——Handler
Handler——是Android给我们提供用来更新UI的一套机制,也是一套消息处理机制,可以发送也可以处理消息 主要作用:1)在新启动的线程中发送消息:2)在主线程中获取.处理消息. (想想银行取钱 ...
- nginx代理TCP端口
1.升级nginx 版本至1.9.0以上 升级流程参考 nginx平滑升级 2.配置编译的时候需要加上 ./configure --prefix=/usr/local/nginx --user=www ...
- 架构师养成记--6.单例和多线程、ThreadLocal
一.ThreadLocal 使用wait/notify方式实现的线程安全,性能将受到很大影响.解决方案是用空间换时间,不用锁也能实现线程安全. 来看一个小例子,在线程内的set.get就是thread ...
- JFinalConfig配置
package com.sandu.common.config; import com.jfinal.config.Constants; import com.jfinal.config.Handle ...
- Python 3.5源码编译安装
系统环境:CentOS 6.8-Minimal 安装Python依赖包: [root@Python src]# yum install zlib-devel bzip2-devel openssl-d ...
- Digester组件
刚认识Digester,记录一下: Digester随着Struts的发展以及其的公用性而被提到commons中独自立项,是apache的一个组件 apache commons-digester.ja ...