我需要使用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()在不安全的来源上不起作用
发布评论