简体   繁体   English

地理位置无法在移动设备上使用,但可以在我的台式机上使用

[英]The geolocation isnt working on mobile but works on my desktop

Im trying to implement geolocation on my project, I already have the api and stuff, all the code necessary, but on mobile whenever I try to access the location it just show and error on the google maps saying "Error: The geolocation service failed." 我正在尝试在我的项目上实现地理位置,我已经拥有api和东西,所有必需的代码,但是在移动设备上,只要我尝试访问该位置,它就会显示并在google地图上显示错误,并显示“错误:地理位置服务失败。 ” but on my desktop it works fine. 但在我的桌面上它可以正常工作。

这里的代码

Was expecting the same thing that happens on my desktop, a prompt asking for permission to access gps but nothing happens 原本希望在我的台式机上发生同样的事情,提示要求访问gps的权限,但没有任何反应

@Pedro Teixeira - If you're running this app from a web server not as a local HTML page. @Pedro Teixeira-如果您是通过网络服务器而不是本地HTML页面运行此应用程序。 Here is why this is not working for you. 这就是为什么这不适合您的原因。

Why Geolocation will not work if your site is not HTTPS or atleast the page you'r calling geolocation is not HTTPS? 如果您的站点不是HTTPS或您所调用的地理位置不是HTTPS的页面,为什么地理定位将不起作用? Chrome has public intent to deprecate powerful features like geolocation on non-secure origins, and we hope that others will follow. Chrome浏览器的公开意图是弃用强大的功能,例如在非安全来源上进行地理位置定位,我们希望其他人能效仿。

Starting with Chrome 50, Chrome no longer supports obtaining the user's location using the HTML5 Geolocation API from pages delivered by non-secure connections. 从Chrome 50开始,Chrome不再支持使用HTML5地理位置API从非安全连接提供的页面中获取用户的位置。 This means that the page that's making the Geolocation API call must be served from a secure context such as HTTPS. 这意味着进行Geolocation API调用的页面必须从安全上下文(例如HTTPS)提供服务。

It is an important issue as it will directly impact any site that requires use of the geolocation API and is not served over https, but it is a change that we do believe is beneficial to all users on the web. 这是一个重要的问题,因为它将直接影响需要使用地理位置API且未通过https进行投放的任何网站,但我们相信此更改对网络上的所有用户都是有益的。 This post should help you understand the reasoning and how to proceed. 这篇文章应该可以帮助您了解原因以及如何进行。

Since when this change is effective? 从什么时候开始这种改变有效? This change is effective as of Chrome 50 (12PM PST April 20 2016). 此更改自Chrome 50(太平洋标准时间2016年4月20日下午12点)开始生效。

Why are we making this change? 我们为什么要进行此更改? Location is sensitive data! 位置是敏感数据! Requiring HTTPS is required to protect the privacy of your users' location data. 需要HTTPS来保护用户位置数据的隐私。 If the user's location is available from a non-secure context, attackers on the network will be able to know where that user is. 如果可以从非安全上下文中获得用户的位置,则网络上的攻击者将能够知道该用户的位置。 This seriously compromises user privacy. 这严重损害了用户隐私。

Who does this affect? 这会影响谁? This affects any page currently using the Geolocation API from pages served over HTTP (non-secure). 这会影响通过HTTP(非安全)提供的页面中当前使用Geolocation API的任何页面。 It also affects HTTPS iframes that use the Geolocation API if they are embedded in HTTP pages. 如果它们嵌入在HTTP页面中,也会影响使用Geolocation API的HTTPS iframe。 (You won't be able to polyfill using a shared HTTPS-delivered frame.) (您将无法使用共享的HTTPS交付框架进行Polyfill。)

Response on the Google Developer Site 在Google开发者网站上的回复

If you would like to use the HTML5 Geolocation API, or if your site already uses the Geolocation API, please migrate the pages making Geolocation API calls to HTTPS, ensuring that they're used in a secure context. 如果您想使用HTML5 Geolocation API,或者您的站点已经在使用Geolocation API,请将将Geolocation API调用的页面迁移到HTTPS,以确保在安全的上下文中使用它们。

There are a number of fallback options available to get a user's location that are not affected by this change, such as Google Maps Geolocation API, GeoIP (as an example, there are other geo based solutions), and a user-entered zip code. 有许多后备选项可用于获取不受此更改影响的用户位置,例如Google Maps Geolocation API,GeoIP(例如,还有其他基于地理的解决方案)以及用户输入的邮政编码。 However, we strongly recommend that the best path to ensure ongoing access to geolocation is to move to HTTPS. 但是,我们强烈建议确保持续访问地理位置的最佳途径是转到HTTPS。

Please follow this link for more information https://developers.google.com/web/updates/2016/04/geolocation-on-secure-contexts-only 请点击此链接以获取更多信息 https://developers.google.com/web/updates/2016/04/geolocation-on-secure-contexts-only

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM