地理位置getCurrentPosition()和watchPosition()在不安全的来源上不起作用

编程入门 行业动态 更新时间:2024-10-26 10:34:58
本文介绍了地理位置getCurrentPosition()和watchPosition()在不安全的来源上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我需要使用php的用户纬度和经度.尝试以下代码.

I need user's Lattitude and longitude using php. try following code.

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Example of HTML5 Geolocation</title> <script type="text/javascript"> function showPosition(){ if(navigator.geolocation){ navigator.geolocation.getCurrentPosition(function(position){ var positionInfo = "Your current position is (" + "Latitude: " + position.coords.latitude + ", " + "Longitude: " + position.coords.longitude + ")"; document.getElementById("result").innerHTML = positionInfo; }); } else{ alert("Sorry, your browser does not support HTML5 geolocation."); } } </script> </head> <body> <div id="result"> <!--Position information will be inserted here--> </div> <button type="button" onclick="showPosition();">Show Position</button> </body> </html>

但是当我在服务器上运行此代码时,我在获取用户纬度和经度时发现了此警告错误.

but when i run this code in server i found this warning error when i fetch User Lattitude and Longitude.

getCurrentPosition()和watchPosition()在不安全的情况下不再起作用 起源.要使用此功能,您应该考虑切换您的 到安全来源(例如HTTPS)的应用程序

getCurrentPosition() and watchPosition() no longer work on insecure origins. To use this feature, you should consider switching your application to a secure origin, such as HTTPS

而此处使用相同的代码. .else建议任何其他获得用户纬度和经度的代码. 谢谢.

while Same code works here..else suggest any other code to get user Latitude and longitude. thanks.

推荐答案

从Chrome 50的不安全来源中删除了地理位置API.

Geolocation API Removed from Unsecured Origins in Chrome 50.

此更改自Chrome 50(太平洋标准时间2016年4月20日中午12点)开始生效.

This change is effective as of Chrome 50 (12PM PST April 20 2016).

Chrome的开发者工具控制台自44版(2015年7月21日发布)以来一直提供警告. 有许多公开声明描述了我们进行此更改的理由(和讨论):

Chrome's developer tools console has been providing warnings since version 44 (released July 21 2015). There have been a number of public announcements that describe the rationale (and discussion) of why we are making this change:

打算通过HTTP弃用一组强大的功能(2015年2月) 打算通过HTTP弃用Geolocation API(2015年11月) Chrome开发者峰会(2016年11月) Chrome Beta Channel发布博客(2016年3月17日) Chrome状态网站 还有许多其他来源强调了这一点:Mobiforge(2016年1月26日),Wired(2016年3月17日),VentureBeat(2016年4月13日).

Intent to deprecate set of powerful features over HTTP (Feb 2015) Intent to deprecate Geolocation API over HTTP (Nov 2015) Chrome Dev Summit (Nov 2016) Chrome Beta Channel release blog (March 17, 2016) Chrome Status website There have been a number of other sources that have highlighted this: Mobiforge (Jan 26, 2016), Wired (March 17, 2016), VentureBeat (April 13, 2016).

在此处阅读更多文档.因此无法在没有HTTPS的情况下使用GeoLocation.

Read More Documentatin here .So thats not possible to use GeoLocation Without HTTPS.

更多推荐

地理位置getCurrentPosition()和watchPosition()在不安全的来源上不起作用

本文发布于:2023-05-24 21:49:24,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/252263.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不安全   地理位置   上不   来源   watchPosition

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!