如何在移动网络浏览器中访问地理位置

时间:2017-04-25 15:55:06

标签: javascript html5 geolocation

我使用的是html5地理位置 我是从文档中做出的

getLocation() {
   if (navigator.geolocation) {
      navigator.geolocation.getCurrentPosition(this.showPosition, this.showError);
   } else {
       alert("geolocation not support");
   }
},

代码正常工作,如果我使用chrome(toogle设备工具栏) 但在移动浏览器中chrome(android)safari(ios)显示错误

  

用户未共享位置

如何解决?

启用手机地理位置

  

UPD:很可能是因为没有ssl证书?

3 个答案:

答案 0 :(得分:2)

并非所有浏览器都内置了相同的API。因此,您必须弄清楚客户端使用的浏览器,并根据所包含的API编写不同的代码。您可以通过检查用户代理来确定他们使用的浏览器。

答案 1 :(得分:1)

使用最新的浏览器更新来获取地理位置,您需要使用

  

SSL证书

用于safari浏览器 answer from this question helped me

答案 2 :(得分:0)

https://whatwebcando.today/上检查哪些浏览器支持它。另外,可能会在操作系统设置中禁用地理位置服务-整个或每个应用程序。