In an extremely simple example I am trying to fetch co-ordinates of user device and plotting the same on google maps in the web page. The example is simple and must run, but however I am finding an error. Can someone help out to solve it?
x = navigator.geolocation;
x.getCurrentPosition(success, failure);
function success(position){
var lat = position.coords.latitude;
var long = position.coords.longitude;
document.getElementById('para1').innerHTML = lat;
document.getElementById('para2').innerHTML = long;
var coords = new google.maps.LatLng(lat, long );
var mapOptions = {
zoom: 15,
center: coords,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById('mapDiv'), mapOptions);
}
function failure(){
alert ("It did not work");
}
<body>
<p id="para1"></p>
<p id="para2"></p>
<div id="mapDiv" style="width:500px;height:500px;"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.googlemap/1.5/jquery.googlemap.min.js"></script>
</body>
Error:
Reference: https://www.youtube.com/watch?v=obOa8fdJ9aQ


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