Geo location getCurrentPosition() and watchPosition() not work on insecure origins

天涯浪子 提交于 2019-12-02 14:18:34

问题


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() 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

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


回答1:


Geolocation API Removed from Unsecured Origins in Chrome 50.

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

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:

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).

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



来源:https://stackoverflow.com/questions/46752618/geo-location-getcurrentposition-and-watchposition-not-work-on-insecure-origi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!